Created
January 12, 2016 19:20
-
-
Save furdarius/d12be7a9f07f8ab39167 to your computer and use it in GitHub Desktop.
split string C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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