Skip to content

Instantly share code, notes, and snippets.

@bddap
Created February 23, 2017 19:45
Show Gist options
  • Save bddap/2ee32678189d2e5b8624a0e0b5509994 to your computer and use it in GitHub Desktop.
Save bddap/2ee32678189d2e5b8624a0e0b5509994 to your computer and use it in GitHub Desktop.
C++ split string on char
vector<string> split(string s, char delimiter) {
vector<string> r;
while (true) {
string::size_type l = s.find(delimiter);
if (l == string::npos) {
r.push_back(s);
break;
}
r.push_back(s.substr(0, l));
s.erase(0, l + 1);
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment