Created
February 23, 2015 13:42
-
-
Save andik/a9d80f460315df6e55b2 to your computer and use it in GitHub Desktop.
C++ string split
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
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) { | |
std::stringstream ss(s); | |
std::string item; | |
while (std::getline(ss, item, delim)) { | |
elems.push_back(item); | |
} | |
return elems; | |
} | |
std::vector<std::string> split(const std::string &s, char delim) { | |
std::vector<std::string> elems; | |
split(s, delim, elems); | |
return elems; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment