Jump to content
  • Advertisement
Sign in to follow this  
Sephirox

problem with ifstream

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

hi there... i am having trouble with ifstream. ok, the problem happens when i close a file and then try opening it again. so.. ifstream in("in.txt"); in.close(); ifstream in2("in.txt");//causes error if(in2.is_open())//-->>false basically, my problem is that i reached the eof, and i want to start from the beginning again (thats why i reopen the file). i know i could just use seekg(0, ios_base::beg) but that also has a problem (in.eof() is still true after calling seekg). i am using vc++ 2005 express beta 2 on winxp please heeelp. thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Creating another file stream isn't needed, all you need to do is invoke std::basic_ios::clear (ifstream inherits it) after you have closed the file stream and before you open it again. You need to do this because the eofbit stream state is still set, calling std::basic_ios::clear resets the stream state back to good state.

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!