Jump to content
  • Advertisement
Sign in to follow this  
random_thinker

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

This topic is 4850 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
Advertisement
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!