Go to recurring questions to learn how to break a string into words, but your method is really correct. The real problem is how you read the input before trying to separate it:
string tempInput;
cin >> tempInput;
cin >> tempInput, , . , stringstream :
std::string tempInput;
std::vector< std::string > tokens;
while ( std::cin >> tempInput ) {
tokens.push_back( tempInput );
}
std::vector< std::string > tokens;
std::copy( std::istream_iterator<std::string>( std::cin ),
std::istream_iterator<std::string>(),
std::back_inserter(tokens) );
. , getline <string> cin >> tempInput:
std::string tempInput;
while ( getline( std::cin, tempInput ) ) {
}