1string s, tmp;
2stringstream ss(s);
3vector<string> words;
4
5// If there is one element (so komma) then push the whole string
6if(getline(ss, tmp, ',').fail()) {
7 words.push_back(s);
8}
9while(getline(ss, tmp, ',')){
10 words.push_back(tmp);
11}
12
1std::string s = "What is the right way to split a string into a vector of strings";
2std::stringstream ss(s);
3std::istream_iterator<std::string> begin(ss);
4std::istream_iterator<std::string> end;
5std::vector<std::string> vstrings(begin, end);
6std::copy(vstrings.begin(), vstrings.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
7