Skip to main content
gamedev.net
🔒 Locked 🎲 GameMaker

File i/o - file pointer problem

Started by donoboso Jun 27, 2006 at 3:26 AM 1 replies 500+ views
Original Post
donoboso
donoboso
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):

//startup

ifstream obj_file(argv[1]);

obj_file.getline(obj_line, 256);

while(!obj_file.eof())
{
    //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.close();
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!
Aardvajk
Aardvajk
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
donoboso
donoboso
Ok, thank you very much. didnt know that (*^_^*)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.