I'm working on my weekly assignment, and have run into a problem that so far no one has been able to help me solve. Basically what I'm doing is reading a text file with multiple sections into an object so it can be printed out later by specific section.
To do this, I have a vector of vectors, which I'm filling with vectors of strings. I'm using nested while loops to read the contents of a text file into this form. Both the separate sections of text as well as the beginning and end of the text are represented by special lines of text (repeated punctuation).
The problem is that, the loops appear to be working fine, reading in values and so forth, until it is time for the outer loop to exit. When this should happen, the loop suddenly starts executing endlessly, outputting whatever seems to have been the last thing in the input stream. I have no idea why this would happen.
Here's the code:
// These are the lines of text which delimit the
//beginning/end of file, as well as the sections of text
const string EQUAL40 = string(40, '=');
const string DASH40 = string(40, '-');
int i = 0; //for testing only
while(line != EQUAL40)
line = "empty";
while((line != DASH40))
//cout << "in do-while \n";
cout << item[i] << endl;
i = 0;
So there it is. What surprises me the most is that the loops seem to execute perfectly fine until the condition to end the outer loop is met.I'd think that, if something like this was going to happen, it would have more predictable behavior, instead of working one way then doing something totally unrelated.
Anyway, I know there's an answer, but I haven't yet found it. Any help with this will be really appreciated. :)