Created
March 24, 2018 13:07
-
-
Save dwburke/cd0d7d785b8a92f6dbfc556adf2cb645 to your computer and use it in GitHub Desktop.
split on token - from https://stackoverflow.com/questions/236129/the-most-elegant-way-to-iterate-the-words-of-a-string
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
#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