CJCoding With Joseph
15free / daySign inCreate account

Write a function void printVec(ostream& out, const vector<int>& v) that writes the elements of v inside square brackets, separated by a comma and a space, followed by a newline. The loop and the brackets are already in the starter; fill in the two commented lines so that the separator is printed before every element except the first. An empty vector prints just [].

Output of printVec(cout, {1, 2, 3}) (see Expected Output).

Do NOT write a main function.

Expected output

[1, 2, 3]
[]
[42]

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

Hints2 available
Topics
Streamsostream
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.