On 28.12.14 20.29, mathewji wrote:
> With:
>
> int day = 0;
> while(true) {
> cout << "number: ";
> cin >> day }
>
> Inputting anything besides an int into day, causes nonstop output of "number: ". I found a solution as:
If no int can be read from cin then the >> operator does nothing but
setting an error flag which you did not check.
> int day = 0;
> while(true) {
> cout << "number: ";
> if (cin >> day) day;
> else break; }
>
> Anyone know why this happens?
Now you checked for the error by implicitly converting cin (istream) to
bool.
Marcel