CJCoding With Joseph
15free / daySign inCreate account

Write Numbers 1 to 5

Write a function void writeNumbers(const string& filename) that opens filename with an ofstream and writes the integers 1, 2, 3, 4 and 5, one number per line (each followed by a newline). The starter opens the stream as out and provides the loop for (int i = 1; i <= 5; i++).

The test reopens the file and prints every line, so the output is exactly what is shown in Expected Output.

Do NOT write a main function.

Expected Output:

1
2
3
4
5
1
2
3
4
5

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

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