I just started learning C++ lately and im experiencing the same problems of 'scanf()' with 'cin' (well i consider them as problems).
'cin' doesn't read characters it can't , and leaves them in the stream just like 'scanf()' with the newline character for example , but i can get rid of the '\n' with no problems so i don't care much about that.
What i care about is , in the following program :
if i enter any character instead of a number , the program would loop infinitely at that point and "Enter a number : " would be all over the screen !!Code:... int num; while(1) { cout << "Enter a number : "; cin >> num; if(num == -1) break; } ...
I'm guessing that when cin\scanf() can't read a character it leaves it in the input stream , then at the next attempt it would try to read it again but still can't and so on... am i guessing right? if not , then whats causing the problem?