← Back to Streams
Question 600
Write a Vector on One Line
Write a Vector on One Line
Write a functionvoid writeVector(const string& filename, const vector<int>& v)that opensfilenamewith anofstreamand writes all the values ofvon 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
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.