std::string s( "My name is Bobby" );
std::string::size_type pos = s.rfind( " " );
std::cout << pos << std::endl;
The output is 10.
EDIT: I think I have understood what is the reason that you got -1. It seems that you are using operator >> to enter str_name. It enters only one word. You should use std::getline( std::cin, str_name ) instead of operator >>.