class Solution {
public:
string reverseWords(string s) {
stringstream ss(s);
string temp = "";
string res = "";
while (ss >> temp) {
cout<<temp<<endl;
res.insert(0, temp + " ");
}
res.erase(res.end() - 1);
return res;
}
};
这种写法是为了熟悉stringstream、insert和erase。