Ignoring the Enter key after the first character is read - C++ File Stream

C++ examples for File Stream:cin

Description

Ignoring the Enter key after the first character is read

Demo Code

#include <iostream>
using namespace std;
int main()// w  ww .j  a v  a 2 s. c o  m
{
   char fkey, skey;
   cout << "Type in a character: ";
   cin.get(fkey);
   cout << "The key just accepted is " << int(fkey) << endl;
   cin.ignore();
   cout << "Type in another character: ";
   cin.get(skey);
   cout << "The key just accepted is " << int(skey) << endl;
   cin.ignore();
   return 0;
}

Result


Related Tutorials