Electrical and Computer Engineering
17 of 23
UAH
CPE 112
End-of-File Controlled Loops
•After a program has read the last piece of data from an input file, the computer is at the end of the file (EOF).
•If we try to input any more values, the stream goes into the fail state.
•We can use the failure of the input stream as a sentinel.
•Example:
– inData >> intVal;
– while (inData)
– {
–   cout << intVal << endl;
–    inData >> intVal;
– }