例子:sdjb,1324
std::string::find (const string& str, size_t pos = 0)
std::basic_string::substr(size_t pos, int len)
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
vector<string> split(string s, string p) {
vector<string> ans;
string str = "";
size_t begin_pos = 0;
size_t find_index = s.find(p, begin_pos);
if(find_index == 0) {
begin_pos = 1;
find_index = s.find(p, begin_pos);
}
while(find_index != string::npos) {
str = s.substr(begin_pos, find_index-begin_pos);
ans.push_back(str);
begin_pos = find_index + 1;
find_index = s.find(p, begin_pos);
}
str = s.substr(begin_pos, s.size()-begin_pos);
ans.push_back(str);
return ans;
}
int main() {
string s = ",234,566,89,";
string p = ",";
vector<string> ans = split(s, p);
for(string & e : ans) cout<<e<<endl;
}