I'm opening a file and reading it using getline(x,y) currently but I want to stop reading the line when I encounter a whitespace and then continue reading from there. Thanks
Formatted input will stop at white space:
std::string str;
while( file >> str)
std::cout << str << std::endl;
Maybe instead you are looking for isspace( int ch)
method:
#include <cctype>
if ( isspace( string.at(i)))
// ... stop
因此,您可能希望从文件中读取每个字符,并使用if
语句将其等于whitespace
,因此请看一下函数getc
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.