Sunday, October 24, 2010

Split string to vector

Saya ambil dari rujukan [1]

Contoh:

string d = "Ahmad 54 34 45";

vector result;

split(d,'\t',result);


vector &split(const string &s, char delim, vector &elems) {
stringstream ss(s);
string item;
while(std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}


Rujukan:

1. http://stackoverflow.com/questions/236129/how-to-split-a-string

No comments:

Post a Comment