Created
October 22, 2022 20:59
-
-
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 " ")
This file contains 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(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