tags:

views:

18

answers:

0

I have seen a couple good ways to find EOF using C++. I have been looking around and pieced this together based off of something I read on cplusplus.com:

ifstream is;
is.open ("test.txt", ios::binary );

// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);

Then you can loop until reaching the EOF:

while(count !=length){ 

count++ }

Would there be any reason NOT to use this techniques because generally I have found.

while(inFile.eof){}

Or

while(inFile){}

Or

using cin.get(ch) or cin.peek(ch) with

while(ch != '\n'){} 

Those all seem to work sometimes but not always. Any professional advice is greatly welcomed.