vector<string> split(const string &str, const string &delim) {
// str要分隔字符串,delim分割字段
vector<string> res;
if (str.empty()) return res;
char *strs = new char[str.length() + 1];
strcpy(strs, str.c_str());
char *d = new char[delim.length() + 1];
strcpy(d, delim.c_str());
char *p = strtok(strs, d);
while (p) {
string s = p;
res.emplace_back(s);
p = strtok(nullptr, d);
}
delete[] strs;
delete[] d;
return res;
}
C++ split函数
最新推荐文章于 2023-07-16 21:37:19 发布