[英]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.