eof in MinGW Developer Studio

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey Guys, I had some sort of a problem while using the "filename.eof()" command mingw. the program never return a "true" value (or '1') when I use eof() so I cannot read a file using the eof condition. I have tried both the while(!infile.eof()) { } and if(infile.eof != 1) { } I even trie this... I had a single word in my file.. ********** Booom!!! ********** but when i did this: infile >> one; infile >> two; cout << infile.eof() the putput was still 0 when i anticipated a 1 as output

Share on other sites
Hey Abhinash,

I was just researching this exact problem this afternoon! (I think).

The problem is, eof isn't set, until you read *after* the end of the file.

// while it's intuitive to say:while (!file.eof()){   file.get();   dosomething();}// what we actually need is something like:while(1){   file.get();   if (file.eof())      break;   dosomething();}

I haven't been able to find anything neater than that.

Hope that helps.

Tim