Count a Character with get
mediumQuestion 590Write a function int countChar(const string& filename, char c) that returns how many times the character c appears in the file. Read the file one character at a time with the stream's get member; spaces and newlines count. For a file containing:
mississippi
countChar(..., 's') returns 4. For the line one two three (two spaces before three), countChar(..., ' ') returns 3.
The test prints the returned count on its own line, for example (see Expected Output).
Do NOT write a main function.
Expected output
4 3
= newline. The output ends with a newline, so print one after the last line.
Hints4 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.