Created
February 3, 2017 03:47
-
-
Save wusuopubupt/febf6379c68ca5368bc17f4e3b0eccd2 to your computer and use it in GitHub Desktop.
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
#include<string> | |
#include<vector> | |
#include<sstream> | |
#include<iostream> | |
std::vector<std::string> split(const std::string& s, char delimiter) { | |
std::string item; | |
std::istringstream is(s); | |
std::vector<std::string> ret; | |
while(std::getline(is, item, delimiter)) { | |
ret.push_back(item); | |
} | |
return ret; | |
} | |
int main(int argv, char **argc) { | |
std::string s = "hello,world,123"; | |
char delimiter = ','; | |
std::vector<std::string> tokens; | |
tokens = split(s, delimiter); | |
int i = 0; | |
while( i < tokens.size() ) { | |
std::cout << tokens[i] << std::endl; | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment