Originally Posted by
smokeyangel
I see a couple of issues with your reader code -- in ReadFromFile() function:
- you are breaking out of the loop before storing the last record in the list.
- you seem not to be skipping newlines at the end of the lines.
I'm surprised it's working at all without the newline skipping. Maybe a platform difference.
By my second point I mean:
Code:
// final iteration through loop
getline(InFile, Designation); //read last record
getline(InFile, Agent);
InFile >> Temperature;
InFile >> Count;
InFile >> Index;
InFile.ignore(100, '\n'); // now at EOF
if(InFile.eof())
break;
// remaining statements are unreachable
// so last record is not stored in List
Temp.SetDesignation( Designation );
Just move the break down a bit.
The other problem is with the iterator ILister. Here:
Code:
cout << "\nLowest Temperature:\t " << GetMinF() //Second problem
<< "\t\t\t" << (*ILister).Convert( GetMinF() );
You are relying on ILister always pointing to a valid list entry when you deference it to call Convert(). This is not true here -- within GetMinF and GetMaxF you use ILister in the for loop, so when you get to here ILister is pointing past the end of the list!
Basically every time you use ILister you need to initialise it first -- because you have lots of for loops that can modify the value, you can't rely on it persisting or having a sensible value. For calls like the above call to Convert() you don't seem to need a particular element -- so you could just use List.begin() I think.
Shout if any of that is unclear.
You were right about the "ILister". I should not be depending on it because it has been used in many for loops. Anyway, I fixed that problem. But, about the ReadFromFile, I am not really sure how it is not storing the last record of the list. Because I am using a "break", right after the user enter the Air Index value, it seems to me that it is recording everything it is supposed to record.
Thank you for your response, Elysia. The code with indentation, indeed, looks really clear and attractive. But, I am not really sure which article you were referring to when you said "I should have understood from the article posted earlier".
But, anyway is there any chance that you could tell me how you indented the code above? I would love to learn it.