Created
February 23, 2017 19:45
-
-
Save bddap/2ee32678189d2e5b8624a0e0b5509994 to your computer and use it in GitHub Desktop.
C++ split string on char
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
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