Skip to content

Instantly share code, notes, and snippets.

@dwburke
Created March 24, 2018 13:07
Show Gist options
  • Save dwburke/cd0d7d785b8a92f6dbfc556adf2cb645 to your computer and use it in GitHub Desktop.
Save dwburke/cd0d7d785b8a92f6dbfc556adf2cb645 to your computer and use it in GitHub Desktop.
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
template<typename Out>
void split(const std::string &s, char delim, Out result) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
*(result++) = item;
}
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, std::back_inserter(elems));
return elems;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment