CJCoding With Joseph
15free / daySign inCreate account

Write a Vector on One Line

Write a function void writeVector(const string& filename, const vector<int>& v) that opens filename with an ofstream and writes all the values of v on a single line, separated by single spaces, followed by one newline. There must be no space before the first value. The vector always holds at least one value.

The test reopens the file and prints every line, so the output for {4, 8, 15} is exactly what is shown in Expected Output.

Do NOT write a main function.

Expected Output:

4 8 15
10 20 30 40

= newline. The output ends with a newline — print one after the last line.

Hints3 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.