I’ve not understood the working of cin. Given the following example
int main() {
int ival;
while (cin >> ival, !cin.eof())
cout << ival << endl;
return 0;
}
If I enter in the standard input the sequence 1 2 3 and then press Enter, I have that sequence in the output. Then, if I enter End of File (^Z) the program exit the loop. But if I enter the following sequence 1 2 3 ^Z and then press Enter, the program gives in output 1 2 3 3 3 3 3 3 3 . . . and loops indefinitely. Why?
Thank you
try using && instead of the comma for your while loop. && will loop while cin >>ival is valid AND while !cin.eof(). The comma is for seperating additional arguments, not adding more conditions