Advertisement Jump to content
Sign in to follow this  

C++ Parsing a file with fields more than one time...

This topic is 4913 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 All, I'm parsing a file and inserting data in fields. The file is used as a report template. I cannot seem to parse it more than once, which I think is a stream problem, but I can't seem to locate the problem. Code follows: using namespace std; int i = 0; char ch; Input in(template_file); // Input is a typedef to an ifstream, with some extensions. for ( i = 0; i < table_.size(); ++i ) { in.seekg(0); // Set to beginning of buffer. while (in.get(ch)) { switch(current_state) { // 'state' machine for parsing the file... } } The above loop parses the file excellently for one loop, but does nothing for the second. I've set 'in.seekg(0)' to try to reset the stream, but this does not appear to be working. Am I missing something here? Alternatively I could move the entire inner loop to a separate private method including 'Input in(template_file)', which would re-open the input file each time locally. There should be a simpler way to do this with the STL. however. Suggestions? --random.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!