单词的数量不确定,因此使用while(cin >> s )读入字符串,并且再用一个变量记录当前最后以后一个字符串的长度即可。
#include <iostream>
#include <string>
int main() {
size_t res = 0;
std::string s;
while(std::cin >> s) res = s.size();
std::cout << res;
}

单词的数量不确定,因此使用while(cin >> s )读入字符串,并且再用一个变量记录当前最后以后一个字符串的长度即可。
#include <iostream>
#include <string>
int main() {
size_t res = 0;
std::string s;
while(std::cin >> s) res = s.size();
std::cout << res;
}