可能重复(foobar.eof()!):
Why is iostream::eof inside a loop condition considered wrong?
eof() bad practice?为什么(foobar的>> X)优于
老师说,我们不应该使用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](http://stackoverflow.com/questions/6512173/ifstream-not-reading-eof-character)以及其他许多人。 – Rapptz