Sign in to follow this  
Abhinash

eof in MinGW Developer Studio

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this