c 2b 2b split string

Solutions on MaxInterview for c 2b 2b split string by the best coders in the world

showing results for - "c 2b 2b split string"
Melody
03 Sep 2018
1std::vector<std::string> split_string(const std::string& str,
2                                      const std::string& delimiter)
3{
4    std::vector<std::string> strings;
5
6    std::string::size_type pos = 0;
7    std::string::size_type prev = 0;
8    while ((pos = str.find(delimiter, prev)) != std::string::npos)
9    {
10        strings.push_back(str.substr(prev, pos - prev));
11        prev = pos + 1;
12    }
13
14    // To get the last substring (or only, if delimiter is not found)
15    strings.push_back(str.substr(prev));
16
17    return strings;
18}
19