Count Words
easyQuestion 581A text file contains words separated by any mix of spaces and newlines, possibly with extra blank space, for example:
the quick brown fox jumps
Write a function int countWords(const string& filename) that returns how many words the file contains; a word is any run of non-whitespace characters. The starter opens the file and declares string word and int count; write the loop.
The test prints the returned count on its own line, for example (see Expected Output).
Do NOT write a main function.
Expected output
5 3
= newline. The output ends with a newline, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
Streamsifstream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.