getline() & stringstream

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main() {
    string s;
    getline(cin, s);
    stringstream ss;
    ss << s;
    //或者 stringstream ss(s);
    while (ss >> s){
        cout << s << "\n";
    }
}

分享本文 Share with friends