Electrical and Computer Engineering
29 of 37
UAH
CPE 112
Reading Characters
withthe get Function
•The >> operator skips any leading white-space characters (such as blanks and new-line characters) while looking for the next data value in the input stream.
•Consider cin >> ch1 >> ch2; and an input stream of R 1. ch1 = ‘R’ ch2 = ‘1’ What if you wanted the blank also? You can’t do it with the extraction operator.
•You can use the get function, which doesn’t skip any characters. cin.get(someChar);
•The argument to the get function must be a character variable.