• ### Announcements

#### Archived

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

# Going back to the beginning of a text file

## Recommended Posts

Ok I''m writing a text parser. I want to do two seperate passes on the file. This means I have to start reading from the top of the file again. My first thought on how to do this was using seekg(I''m using an ifstream btw) so I''d go like this MapFile.seekg(0,ios::beg); It didn''t work. I then thought I could try closing the file then re-opening so it started reading from the top again. So I used this MapFile.close; MapFile.open("thing.map"); It still didn''t work. Can anybody tell me the way you''re meant to do it(or at least a way that works)?

##### Share on other sites
If you hit the end of file, the failbit was set and you need to clear it:
MapFile.clear();MapFile.seekg(0,ios::beg);

Enjoy!

Thanks

• ### Forum Statistics

• Total Topics
628293
• Total Posts
2981869

• 11
• 10
• 10
• 11
• 17