Skip to content

Instantly share code, notes, and snippets.

@aeppert
Created September 8, 2015 19:13
Show Gist options
  • Select an option

  • Save aeppert/7384d720194219547b1e to your computer and use it in GitHub Desktop.

Select an option

Save aeppert/7384d720194219547b1e to your computer and use it in GitHub Desktop.
split_tokens in C++
#include <string>
#include <sstream>
#include <vector>
std::vector<std::string> split_tokens(const std::string &s, char delim) {
std::stringstream ss(s);
std::string item;
std::vector<std::string> tokens;
while (getline(ss, item, delim)) {
if(item.length() > 0) {
tokens.push_back(item);
}
}
return tokens;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment