Skip to content

Instantly share code, notes, and snippets.

@samos123
Created June 4, 2014 13:16
Show Gist options
  • Save samos123/84b1a4339d1ab2eeecd6 to your computer and use it in GitHub Desktop.
Save samos123/84b1a4339d1ab2eeecd6 to your computer and use it in GitHub Desktop.
C++ split string by delimiter
// Taken from http://stackoverflow.com/a/236803/376445
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment