cin vs getline

Hi guys so I know cin reads input up until any white space,and getlien reads the whole line including the /n character but so using cin then getline after will leave a /n in the buffer and getline will get an empty string

but how come when you use multiple cins one after another it does not print a new line as I thought a /n is left in the buffer

the code below works just fine and does not skip the second input where as if we used a getline for two (if two was a string,can't use getline for ints) we would get an empty string

thanks
1
2
3
  int one,two;
  cin >> one;
  cin >> two
Formatted input (cin >> something) by default skips leading whitespace (as if it were written cin >> ws >> something). Hence, any leftover newlines get eaten.
Topic archived. No new replies allowed.