Skip to content

Instantly share code, notes, and snippets.

@furdarius
Created January 12, 2016 19:20
Show Gist options
  • Save furdarius/d12be7a9f07f8ab39167 to your computer and use it in GitHub Desktop.
Save furdarius/d12be7a9f07f8ab39167 to your computer and use it in GitHub Desktop.
split string C++
vector< string > split(string str)
{
std::vector<std::string> v ; //Use vector to add the words
std::size_t prev_pos = 0, pos;
while ((pos = str.find_first_of(",;", prev_pos)) != std::string::npos)
{
v.push_back(str.substr(prev_pos, pos-prev_pos));
prev_pos = pos + 1;
}
v.push_back(str.substr(prev_pos, std::string::npos));
return v;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment