Created
September 8, 2015 19:13
-
-
Save aeppert/7384d720194219547b1e to your computer and use it in GitHub Desktop.
split_tokens in 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
| #include <string> | |
| #include <sstream> | |
| #include <vector> | |
| std::vector<std::string> split_tokens(const std::string &s, char delim) { | |
| std::stringstream ss(s); | |
| std::string item; | |
| std::vector<std::string> tokens; | |
| while (getline(ss, item, delim)) { | |
| if(item.length() > 0) { | |
| tokens.push_back(item); | |
| } | |
| } | |
| return tokens; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment