Skip to content

Instantly share code, notes, and snippets.

@nikuuchi
Created December 5, 2011 04:39
Show Gist options
  • Select an option

  • Save nikuuchi/1432320 to your computer and use it in GitHub Desktop.

Select an option

Save nikuuchi/1432320 to your computer and use it in GitHub Desktop.
split関数の自作
#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