Sign in to follow this  

Strange ifstream behaviour?

This topic is 3596 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

Hiya, I've noticed that once you read past the end of a file using std::ifstream and the 'eof' bit is set, it's not cleared when you call seekg() to seek to another position, unlike the old C functions... is this correct? Is there a way to change this behaviour? What do you think about using C file routines in a C++ program? I'm guessing there's a small performance increase (probably negligible). I'm writing some low-level file reader classes, which just need to read a set number of bytes into a buffer - is there any need to use an ifstream? Just hoping someone could comment. Many thanks for any help!

Share this post


Link to post
Share on other sites
AFAIK, there's no way to change that behavior. The advantage of using a ifstream over the C style FILE * functions is that the ifstream will clean up after itself in the event of an exception. RAII is your friend.

Share this post


Link to post
Share on other sites

This topic is 3596 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.

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