Jump to content
  • Advertisement
Sign in to follow this  

File i/o - file pointer problem

This topic is 4524 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, i have a problem with file i/o. I need to read a file twice (cause of memory allocation) but i can't set the file Pointer to the beginning of the file after reading it. It always replies a EOF. The programm should convert a Wavefront OBJ file to my own file format. I tried the following things (everything is simplified):

ifstream obj_file(argv[1]);

obj_file.getline(obj_line, 256);

    //read and count things
    obj_file.getline(obj_line, 256);

//allocate memory

//obj_file.seekg(0, ios::beg);  //does not work (still eof)
obj_file.seekg((streampos)0); //does not work (still eof)

obj_file.open(argv[1], ios::in); //does not work (still eof)

The only thing that worked was that i created a new ifstream like for example obj_file2 and read the same file again, but thats somehow stupid and in some casesnot practical (when you need to read lots of files). I think i overloocked something really simple, but i dont get it. Thanks for your help!

Share this post

Link to post
Share on other sites
I believe you have to call istream.clear() after you set the position to 0, to clear out the eof flag, but someone else can probably confirm this or give more details.

HTH Paul

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!