C++ Parsing a file with fields more than one time...
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement