[英]How do you stop reading integer from text file when encounter negative integer?
[英]How do I stop reading a line when I encounter a whitespace?
我正在打开一个文件,当前使用getline(x,y)读取它,但是我想在遇到空白时停止读取该行,然后继续从那里读取。 谢谢
格式化的输入将在空格处停止:
std::string str;
while( file >> str)
std::cout << str << std::endl;
也许相反,您正在寻找isspace( int ch)
方法:
#include <cctype>
if ( isspace( string.at(i)))
// ... stop
因此,您可能希望从文件中读取每个字符,并使用if
语句将其等于whitespace
,因此请看一下函数getc
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.