Skip to content

Instantly share code, notes, and snippets.

@hechen
Created October 15, 2019 09:04
Show Gist options
  • Save hechen/b8a1ef21dba75c7053c6dcab8cf5a883 to your computer and use it in GitHub Desktop.
Save hechen/b8a1ef21dba75c7053c6dcab8cf5a883 to your computer and use it in GitHub Desktop.
C++ dose not support split function. Use stringstream.
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