1、采用string 获取整个字符串的长度,在反向查找第一个空格的position,用长度减去position(从0计数)再加上1;
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
getline(cin, str);
long strLen = str.length();
int pos = str.rfind(' ');
cout << (strLen - pos - 1) << endl;
return 0;
}