| 24 | } |
| 25 | |
| 26 | void find_words(vector<string>& words, const string& text, const string& separators) |
| 27 | { |
| 28 | size_t start {text.find_first_not_of(separators)}; // First word start index |
| 29 | |
| 30 | while (start != string::npos) // Find the words |
| 31 | { |
| 32 | size_t end{ text.find_first_of(separators, start + 1); } // Find end of word |
| 33 | if (end == string::npos) // Found a separator? |
| 34 | end = text.length(); // No, so set to end of text |
| 35 | |
| 36 | words.push_back(text.substr(start, end - start)); // Store the word |
| 37 | start = text.find_first_not_of(separators, end + 1); // Find 1st character of next word |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void list_words(const vector<string>& words) |
| 42 | { |