1. 字符串分割函数
// 字符串的分割
vector<string> split(string str, string separator)
{
vector<string> result;
int cutAt;
while( (cutAt = str.find_first_of(separator)) != str.npos )
{
if(cutAt > 0)
{
result.push_back(str.substr(0, cutAt));
}
str = str.substr(cutAt + 1);
}
if(str.length() > 0)
{
result.push_back(str);
}
return result;
}
2. 调用
std::vector<std::string> result = split("aaa,bbbb:ccc:dddd,eee:",",:");
3. 结果