Word Counts to File
hardQuestion 621Write a function void writeWordCounts(const string& src, const string& dst) that reads every whitespace-separated word from the file src, counts how many times each word appears, and writes the result to the file dst (created or truncated): one line per distinct word, in alphabetical order, as the word, a space, its count, then a newline. Words are compared exactly (case-sensitive). Use a map<string, int>.
For a source file containing apple pear apple the file dst must contain exactly:
apple 2
pear 1
Do NOT write a main function.
Expected output
apple 2 pear 1 a 2 b 2 c 1
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Streamsofstream
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.