How are you using it? What .eof()
will tell you is that the stream has already hit the end of file, that it has tried to read data that isn't there.
This isn't usually what you want. Usually, you want to know that you are hitting the end of file, or that you are about to hit the end of file, and not that you have already hit it. In a loop like:
while(!f.eof())
{
f >> /* something */;
/* do stuff */
}
you are going to attempt to read input in and fail, and then you are going to execute everything in /* do stuff */
, and then the loop condition fails and the loop stops.
Another problem with that loop is that there's other ways input can fail. If there's an error condition on the file that isn't EOF, .fail()
will return true
but .eof()
won't.