I've read and tried the suggestions made on this forum and others. They all sound like they should sove this problem, but it persists. I'm a tutor and trying to help a student. I know i must be missing something: Here is my code:
/* data in file
2 5
12 76
1x 87
17 4
*/
while (fin >> n1 >> n2)
{
bool failed = fin.fail();
if (!failed )
{
total = n1 + n2;
grandTotal += total;
cout << n1 << " + " << n2 << " = " << total << endl;
}
else
{
cout << "Error in line: " << endl;
fin.clear();
fin.ignore(std::numeric_limits<streamsize>::max(), '\n');
}
}
When it encounter the third line of data, it displays "error in line" but then it doesn't read any further, it just drops out of the read loop as though it has reached end of file.