</pre><pre name="code" class="cpp">int split(const string& src, const string& separator, vector<string>& dest)
{
string::size_type pos = 0;
string::size_type start = 0;
dest.clear();
do{
start = src.find_first_not_of(separator, pos);
if (start == string::npos)
break;
pos = src.find_first_of(separator,start);
if(pos != string::npos)
{
dest.push_back(src.substr(start, pos-start));
}
else
{
dest.push_back(src.substr(start));
break;
}
}while(1);
return dest.size();
}
int main(void)
{
int cnt;
string str = " hello,xxx fk sjf lj\n";
string sep = ", ";
vector <string> dest;
cnt = split(str, sep, dest);
for(int i=0; i<cnt; i++)
{
printf("%s\n", dest[i].c_str());
}
return 0;
}