I am trying to write a program which gets user\'s input in a specific way. First, I input a word which contains no space; Then, I input another word which may contains space; An
The std::getline function does not skip whitespace like the normal input operator >>
does. You have to remove leading (and possible trailing?) whitespace yourself.
Removing the leading whitespace can be done by first finding the first non-whitespace character (with e.g. std::find_if) and then get a substring from that position to the rest (with std::string::substr).
Or as dyp suggests, use std::ws. The linked reference have a very good example how to use it.