// infinite loop to read and handle a line of data
for (;;) {
// do any initializing
infile >> firstThingOnTheLine;
if (infile.eof()) break;
// read the rest of the line
// do whatever with data
}
Often reading is done in a routine. In that case, exit both.
This loop is similar to that situation.
for (;;) {
// do any initializing
obj.setdata(infile); // method finishes reading
if (infile.eof()) break;
// do whatever with obj
}
void objClass::setdata(istream& infile) {
infile >> firstThingOnTheLine; // so EOF char is read
if (infile.eof()) return; // determine no more data
// probably read more data to fill rest of object
}