Say ignore before talking about CIN this I/o input keyword.
CIN requires a "carriage return" to submit the data!!!!! ----------this is very important!
#include <iostream>using namespacestd;voidMain () {intA; Cin.ignore (1,'\ n'); CIN>>A; cout<<a<<Endl; intb; Cin.ignore (2,'\ n'); CIN>>b; cout<<b<<Endl; intC; Cin.ignore (2,'\ n'); CIN>>B; cout<<c<<Endl;}
I entered in turn
123 return Car 123 return car 123 return car
Last output: 23
123
123
The following explains why the following ignore output such a result:
1, enter the first 123 is because the front does not enter a carriage return
2. After you lose the first 123, you will definitely enter a carriage return.
Because CIN this thing asks to submit the data with the carriage return, Cheng continues to execute, this time executes to the Ignore function, it is directly to judge your input buffer, then found the first 123 after the carriage return, therefore the Ignore function is invalid
3, so after you enter any character, with a carriage return will be directly output
C + + Cin.ignore ()