c++中分割函数的实现,支持以空格进行字符串分割
1、函数实现如下:
void split(std::string& s,std::string& delim,std::vector<std::string>* ret)
{
size_t last = 0;
size_t index = s.find_first_of(delim,last);
while(index != string::npos)
{
ret->push_back(s.substr(last,index-last));
last= index+1;
index = s.find_first_of(delim,last);
}
if(index-last > 0)
{
ret->push_back(s.substr(last,index-last));
}
}