stringstream

#include<bits/stdc++.h>
using namespace std;
int main()
{
//1,2,3,4,5
//如何分割逗号间隔的字符串
string str;
getline(cin,str);
stringstream ss(str);
string str_num;
vector<int> vec;
while(getline(ss,str_num,','))
{
vec.push_back(stoi(str_num));
}
for(int i=0; i<vec.size(); i++)
{
cout<<vec[i]<<" ";
}

return 0;
}

find & substr

#include<bits/stdc++.h>
using namespace std;
int main()
{
//1,2,3,4,5
//如何分割逗号间隔的字符串
string str;
getline(cin,str);
str+=",";
vector<int> vec;
while(str.find(',')!=-1)
{
int pos=str.find(',');
vec.push_back(stoi(str.substr(0,pos)));
str=str.substr(pos+1);
}
for(int i=0; i<vec.size(); i++)
cout<<vec[i]<<" ";
cout<<endl;


return 0;
}