Created
June 4, 2014 13:16
-
-
Save samos123/84b1a4339d1ab2eeecd6 to your computer and use it in GitHub Desktop.
C++ split string by delimiter
This file contains hidden or 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
// 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