![](/img/trans.png)
[英]How do you stop reading integer from text file when encounter negative integer?
[英]When do I stop reading from a file?
some_file.good()
在读取文件中的最后一个条目后,或者在尝试读取之后是否返回false
? 那就是我应该写的
while (input.good())
{
getline(input, line);
// ...process
}
要么
getline(input, line);
while (input.good())
{
// ...process
getline(input, line);
}
?
试图超越那个......
你可以尝试:
while(getline(input, line))
{
// do stuff with line
}
应该添加,该流实现operator!
,它会检查您通常会使用的标志。 getline
的返回是输入流,但由于运算符,会检查标志。
如前所述,当没有更多行时,getline返回零。 如果设置了EOF标志(即在流上到达文件末尾eof()
,方法eof()
返回true:
if(input.eof())
{
// end of file
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.