• Advertisement

Archived

This topic is now archived and is closed to further replies.

Fstream alternative to rewind?

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

Is there an fstream alternative to the stdio function rewind()?. I am using an fstream and need to move the file pointer back to the start of the file. the only way i know how to do this at the moment is to close the stream and then open it again. Can someone please help me out. Kind regards in advance.

Share this post


Link to post
Share on other sites
Advertisement
istreams have the seekg function, ostreams have seekp.

Example:
    
is.seekg(0);
is.seekg(0, ios::beg); // same as above

is.seekg(10, ios::cur); // current position + 10

is.seekg(-10, ios::end); // 10 bytes before eof



I hope this helps.

Share this post


Link to post
Share on other sites
Do I have to do anything else besides move the file pointer to the start of a file to read it another time? I am asking this because after one function has finished reading it I call fin.seekg(0, ios::beg) in the next function but it doesn''t detect any strings in the file the second time it is read.

Share this post


Link to post
Share on other sites

  • Advertisement