Jump to content
  • Advertisement
Sign in to follow this  
Abhinash

eof in MinGW Developer Studio

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!