Discuss Ifstream's eof() in the C Programming forum on Dev Shed. Ifstream's eof() C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: 20 h 44 m 41 sec
Reputation Power: 10
I've heard a few times that ifstream's eof() function shouldn't be used due to some innacurracy or unexpected behavoir, and that there was another way to check the file, but couldn't remember what it was. Any help?
Time spent in forums: 1 Week 1 Day 6 h 20 m 50 sec
Reputation Power: 208
I do not know any unexpected behaviour related to eof(). But, you could also use Read.good(), which also detects other errors, not just eof. Anyways, I think you should first read from the stream, and then check if the EOF was encountered. If you first check for EOF, and then read, nothing says that the thing you read after the check is not EOF.
IE, perhaps trying:
if(Read.eof()) //previous get returned EOF...
If you miss that check after reading from file, and then try use what you read, it may not work as expected (in case the file ended).
mm.. I hope I am clear... Although at this hour it seems quite impossible to me to be understandable :/