1void tokenize(string &str, char delim, vector<string> &out)
2{
3 size_t start;
4 size_t end = 0;
5
6 while ((start = str.find_first_not_of(delim, end)) != string::npos)
7 {
8 end = str.find(delim, start);
9 out.push_back(str.substr(start, end - start));
10 }
11}
12
13int main()
14{
15 string s="a;b;c";
16 char d=';';
17 vector<string> a;
18 tokenize(s,d,a);
19 for(auto it:a) cout<<it<<" ";
20
21 return 0;
22}
1// splits a std::string into vector<string> at a delimiter
2vector<string> split(string x, char delim = ' ')
3{
4 x += delim; //includes a delimiter at the end so last word is also read
5 vector<string> splitted;
6 string temp = "";
7 for (int i = 0; i < x.length(); i++)
8 {
9 if (x[i] == delim)
10 {
11 splitted.push_back(temp); //store words in "splitted" vector
12 temp = "";
13 i++;
14 }
15 temp += x[i];
16 }
17 return splitted;
18}