Problem with Mixing cin and cin.get

  1. 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.
    // Suppose the user types as input:
    // 12 and press enter and a c and press enter.
    #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;
    }