using namespace std; template<typename T> split(const T & str, const T & delimiters, vector<T>& result) { vector<T> v; T::size_type start = 0; auto pos = str.find(delimiters, start); while(pos != T::npos) { if(pos != start) // ignore empty tokens v.emplace_back(str, start, pos - start); start = pos + delimiters.length(); pos = str.find(delimiters, start); } if(start < str.length()) // ignore trailing delimiter v.emplace_back(str, start, str.length() - start); // add what's left of the string return v; }