Created
October 15, 2019 09:04
-
-
Save hechen/b8a1ef21dba75c7053c6dcab8cf5a883 to your computer and use it in GitHub Desktop.
C++ dose not support split function. Use stringstream.
This file contains 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
template<typename T> | |
void split(const std::string &s, char delim, T output) { | |
std::istringstream iss(s); | |
std::string item; | |
while(getline(iss, item, delim)) { | |
*output++ = item; | |
} | |
} | |
std::vector<std::string> split(const std::string &s, char delim) { | |
std::vector<std::string> result; | |
split(s, delim, std::back_inserter(result)); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment