#include <iostream> using namespace std; #include <string> #include <vector> #include <sstream> int main() { string in; getline(cin, in); istringstream is(in); string word; vector<string> ws; while (is >> word) { if (word[0] == '"') { if (word[word.size() - 1] == '"') { word.erase(word.begin()); word.erase(word.end()-1); ws.push_back(word); } else { string str; word.erase(word.begin()); str += word; do { is >> word; str = str + " " + word; } while (word[word.size() - 1] != '"'); str.erase(str.end()-1); ws.push_back(str); } } else { ws.push_back(word); } } cout << ws.size() << endl; for(auto & w : ws){ cout << w << endl; } }
比较标准的输入处理
要记得去除头尾的引号