Example - Split a Line into Words
void split (const string & text, const string & separators, list<string> & words) // split a string into a list of words text and separators are input, // list of words is output { int textLen = text.length(); // find first non-separator character int start = text.find_first_not_of(separators, 0); // loop as long as we have a non-separator character while ((start >= 0) && (start < textLen)) { // find end of current word int stop = text.find_first_of(separators, start); // check if no ending character if ((stop < 0) || (stop > textLen)) stop = textLen; // add word to list of words words.push_back (text.substr(start, stop - start)); // find start of next word start = text.find_first_not_of (separators, stop+1); }