CJCoding With Joseph
15free / daySign inCreate account

Write Only Evens

Write 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 — 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.