- #36
willem2
- 2,127
- 391
If the << operator can't parse the input as a number, it won't consume the input.yungman said:BUT, I still have an issue. I am supposed to put -1 to signal I want to quit after entering the numbers. BUT if I hit other key like 'q', it will run non stop and I can see the cmd screen keep rolling and rolling until I close the cmd window. Why?
You need to test cin.fail() to see if reading a number worked, and if it didn't work, either stop reading more numbers, or use cin.ignore() to consume the wrong input until you can succesfully read a number again.