MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / find_words

Function find_words

Examples/NoModules/Chapter 08/Ex8_08.cpp:26–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26void 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
41void list_words(const vector<string>& words)
42{

Callers 1

mainFunction · 0.70

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected