Skip to content

Instantly share code, notes, and snippets.

@classmember
Created October 22, 2022 20:59
Show Gist options
  • Save classmember/72abd81877f2e35bc1b55b29545e8e52 to your computer and use it in GitHub Desktop.
Save classmember/72abd81877f2e35bc1b55b29545e8e52 to your computer and use it in GitHub Desktop.
split( string ) function which returns vector<string> based on the string passed in to act as a separator (like " ")
vector<string> split(const string &str) {
vector<string> tokens;
string::size_type start = 0;
string::size_type end = 0;
while ((end = str.find(" ", start)) != string::npos) {
tokens.push_back(str.substr(start, end - start));
start = end + 1;
}
tokens.push_back(str.substr(start));
return tokens;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment