chpicker
Programmer
- Apr 10, 2001
- 1,316
Does anyone know how to clear the input buffer of the cin object? Take this example:
What ends up happening is this. If the user enters 2 characters at the first prompt, the compiler assigns the first character to Selection and holds onto the second. When the second cin is reached, the program won't wait for the user, since it already has that second character in the buffer. It simply assigns that second character to the second Selection and the program continues on its way.
What I want it to do is take the first character entered by the user and discard the rest. Does iostream have a built-in way to do this?
Code:
char Selection;
cout<<"Please select a letter: ";
cin>>Selection;
cout<<"You chose "<<Selection<<endl;
cout<<"Now choose another: ";
cin>>Selection;
cout<<"You chose "<<Selection<<endl;
return;
What I want it to do is take the first character entered by the user and discard the rest. Does iostream have a built-in way to do this?