C++ Split String By Space into Vector
std::string s = "What is the right way to split a string into a vector of strings"; std::stringstream ss(s); std::istream_iterator<std::string> begin(ss); std::istream_iterator<std::string> end; std::vector<std::string> vstrings(begin, end); std::copy(vstrings.begin(), vstrings.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
Source: stackoverflow.com
split string on character vector C++
string s, tmp; stringstream ss(s); vector<string> words; // If there is one element (so komma) then push the whole string if(getline(ss, tmp, ',').fail()) { words.push_back(s); } while(getline(ss, tmp, ',')){ words.push_back(tmp); }
Source: stackoverflow.com