Created
October 31, 2019 03:24
-
-
Save abc126/d4856fa6ea2a0b142a9d2053dfb66486 to your computer and use it in GitHub Desktop.
split string c++
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
| void split(const string& s, vector<string>& tokens, const string& delimiters = " ") | |
| { | |
| string::size_type lastPos = s.find_first_not_of(delimiters, 0); | |
| string::size_type pos = s.find_first_of(delimiters, lastPos); | |
| while (string::npos != pos || string::npos != lastPos) { | |
| tokens.push_back(s.substr(lastPos, pos - lastPos));//use emplace_back after C++11 | |
| lastPos = s.find_first_not_of(delimiters, pos); | |
| pos = s.find_first_of(delimiters, lastPos); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment