使用sstream中的stringstream函数,按照指定字符分割字符串
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
//需要切割的字符串
string str;
//按照,分割字符串
vector<string> myStr;
stringstream ss(str);
string tmp;
while (getline(ss, tmp, ',')) {
myStr/push_back(tmp);
}
//打印分割后的字符串
for (string s : myStr) {
cout << s << end;
}
return 0;
}