1std::vector<std::string> split(const string& input, const string& regex) {
2 // passing -1 as the submatch index parameter performs splitting
3 std::regex re(regex);
4 std::sregex_token_iterator
5 first{input.begin(), input.end(), re, -1},
6 last;
7 return {first, last};
8}
9
1auto const str = "The quick brown fox"s;
2auto const re = std::regex{R"(\s+)"};
3auto const vec = std::vector<std::string>(
4 std::sregex_token_iterator{begin(str), end(str), re, -1},
5 std::sregex_token_iterator{}
6);
7
1//the program take input as string and delimiter is ','.
2//delimiter can be changed in line 9;
3
4std::vector<std::string> tokenise(const std::string &str){
5 std::vector<std::string> tokens;
6 int first = 0;
7 //std::cout<<"aditya";
8 while(first<str.size()){
9 int second = str.find_first_of(',',first);
10 //first has index of start of token
11 //second has index of end of token + 1;
12 if(second==std::string::npos){
13 second = str.size();
14 }
15 std::string token = str.substr(first, second-first);
16 //axaxax,asas,csdcs,cscds
17 //0123456
18 tokens.push_back(token);
19 first = second + 1;
20 }
21 return tokens;
22}