#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
// getline()读取整行,便于字符串流分割
string line;
getline(cin, line);
// 用istringstream创建输入字符串流对象
vector<string> words;
string word;
istringstream iss(line);
// 字符串分割成单词
while (iss >> word) {
words.push_back(word);
}
string last_word = words.back();
cout << last_word.size() << endl;
}
// 64 位输出请用 printf("%lld")
- getline():用getline()获取一行有空格的字符串。
- istringstream:分割字符串用字符串流对象和while循环。
- back():从字符数组words中获取最后一个单词用back()。
- word.size():最推荐的返回字符串大小的函数。