c++中对于string类型的串,用cin无法读入空格,要读入包含空格的串,要使用getline(cin,s)方法 #include <iostream> #include <string> using namespace std; int returnLast(string s) { int lens = 0; for(int i = 0; i < s.size(); i++) { if(s[i] == ' ') { lens=0; } else if(s[i] != '\n'){ lens++; } } return lens; } int main() { ...