Write Only Evens
mediumQuestion 609Write a function int writeEvens(const string& filename, const vector<int>& v) that opens filename with an ofstream and writes only the even values of v, in their original order, on a single line separated by single spaces, with no space before the first value, followed by one newline. It returns how many values it wrote and prints nothing itself. Every test vector contains at least one even number.
For v = {1, 4, 3, 6} the test prints the returned count, then reopens the file and prints every line (see Expected Output).
Do NOT write a main function.
Expected output
2 4 6 3 2 8 10
= 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.