CJCoding With Joseph
15free / daySign inCreate account

Word Counts to File

Write 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 — print one after the last line.

Hints4 available
Topics:
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.