Created
December 5, 2011 04:39
-
-
Save nikuuchi/1432320 to your computer and use it in GitHub Desktop.
split関数の自作
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 <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| //split() | |
| void split(string str,string delim,vector<string> *v){ | |
| int i=0; | |
| while((i = str.find_first_of(delim)) != string::npos){ | |
| v->push_back(str.substr(0,i)); | |
| str = str.substr(i+1); | |
| } | |
| v->push_back(str); | |
| } | |
| //test for split | |
| int main(int argc, char *argv[]) | |
| { | |
| string str = "aaa,bbb,ccc"; | |
| string delim = ","; | |
| vector<string> *v = new vector<string>(); | |
| split(str,delim,v); | |
| std::cout << v->at(0) << " " << v->at(1) << " "<< v->at(2) << std::endl; | |
| delete v; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment