C++ Library Reference

Reading Any Single Character

In addition to using the char extractor, you can get a single character with either form of the get member function. For example:


char c; 
cin.get(c); // leaves c unchanged if input fails

int b;
b = cin.get(); // sets b to EOF if input fails


Note -

Unlike the other extractors, the char extractor does not skip leading whitespace.


Here is a way to skip only blanks, stopping on a tab, newline, or any other character:


int a; 
do {
    a = cin.get();
   }
while( a == ' ' );