The \n
is left in the input stream as per the way operator>>
is defined for std::string
. The std::string
is filled with characters from the input stream until a whitespace character is found (in this case \n
), at which point the filling stops and the whitespace is now the next character in the input stream.
You can also remove the \n
by calling cin.get()
immediately after cin>>str
. There are many, many different ways of skinning this particular I/O cat, however. (Perhaps a good question in and of itself?)