【发布时间】:2012-12-29 03:23:52
【问题描述】:
可能重复:
Why is iostream::eof inside a loop condition considered wrong?
eof() bad practice?
我的老师说我们不应该使用 EOF 来读取文本文件或二进制文件信息,而应该使用 (afile>>x)。他没有解释原因,谁能给我解释一下。谁能解释一下这两种不同的阅读方式有什么区别
//Assuming declaration
//ifstream foobar
( ! foobar.eof() )
{
foobar>>x; // This is discouraged by my teacher
}
while (foobar>>x)
{
//This is encouraged by my teacher
}
【问题讨论】:
-
this 和许多其他人。
标签: c++ text-files binaryfiles