#include <iostream> #include <vector> #include <sstream> using namespace std; vector<string> split(string s,char token){ stringstream iss(s); string word; vector<string> vs; while(getline(iss,word,token)){ vs.push_back(word); } return vs; } int main() { string s1 = "aaa,sss,ddd,fff"; vector<string> s2 = split(s1, ','); cout << s1; for(int i=0;i<s2.size();i++) { cout<<s2[i]<<endl; } system("pause"); return 0; }
结果: