Problem with Mixing cin and cin.get
-
Mixing cin with cin.get can cause annoying and hard-to-find problems.
For example, consider the following program:
// Illustrate problems when cin is used together with get.
#include <iostream>
using namespace std;
int main( )
{
int num;
char ch;
cout << "Enter an integer: ";
cin >> num;
cout << "You entered the integer: " << num << endl;
cout << "Enter a character: ";
//cin >> ch;
cin.ignore(10,'\n'); // need this line to work
cin.get(ch);
cout << "You entered the character: " << ch << endl;
return 0;
}