0

For example, if write those statements in code:

char a[10];
char b[10];
cin>>a;
cin>>b; 

cin>>b; doesn't see Enter key that was pressed after typing, for example, Hello

but when instead cin>>b; write cin.get(b, 10); then cin.get(b, 10); reads Enter key from previous statement.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157
Sunrise
  • 1,311
  • 3
  • 18
  • 28

1 Answers1

6

Working under the assumption that a and b are arrays of char here, because otherwise your question does not make sense.

get is an "unformatted" input function, meant to read the input as it comes into the stream. That's why it reads the newline.

>> is a "formatted" input function, meant to read a specific type of data in a natural way. In particular, >> with a char array reads a single word, i.e. a sequence of characters not containing whitespace. This is why it stops reading when it encounters the newline, which is whitespace.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157