CJCoding With Joseph
15free / daySign inCreate account

Write CSV

Write a function void writeCsv(const string& filename, const vector<string>& names, const vector<int>& scores) that opens filename with an ofstream and writes one line per index i: names[i], a comma (no spaces around it), scores[i], then a newline. The two vectors always have the same length. Do not write a header line.

For names {"Bob", "Amy"} and scores {90, 85} the file must contain exactly:
Bob,90
Amy,85

Do NOT write a main function.

Expected Output:

Bob,90
Amy,85
Zed,100
Eve,72
Max,0

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