In my knowledge, when I write cin >> a
command, program will wait user enter some characters until encounter newline character \n
. That characters will be put into stdin
. After that, cin
will take fist character and put it into a
variable.
I wrote this program to put 2 characters into stdin and use 2 cin commands get them to show:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
char input;
char input_next;
cout << "Please enter a character from your keyboard: ";
cin >> input;
cout << input << endl;
cin >> input_next;
cout << input_next << endl;
return 0;
}
Case 1: I enter string "KH" and press enter button. It show K and H.
Please enter a character from your keyboard: KH
K
H
Press <RETURN> to close this window...
Case 2: I enter character "K" and press enter button. It show K and wait I enter more character. It doesn't show newline character (enter button). Why?