cin >> leaves extra new line in buffer?

I switched to using cin >> instead of getchar in my program thinking it automatically deals with the annoying extra newline char that getchar leaves in the buffer. everything was fine and dandy as long as the the next attempt to get a char was also using cin. but when i tried to use gets() after cin, i noticed that the program wasnt blocking at gets() and waiting for user input, but instead just moving right past it.

so what is really going on here? is cin supposed to take the new line character out of the buffer after it reads the std in?
is cin supposed to take the new line character out of the buffer after it reads the std in?
No.

std::getline() might interest you.
Robust, well-written user input will typically use getline() to get string input, then validate and parse it using a stringstring. This also solves newline and fail state problems on the standard input.

Hope this helps.
Duaos meant stringstream up there I believe.
Topic archived. No new replies allowed.