← Back to Streams
Question 599
Write Numbers 1 to 5
Write Numbers 1 to 5
Write a functionvoid writeNumbers(const string& filename)that opensfilenamewith anofstreamand writes the integers 1, 2, 3, 4 and 5, one number per line (each followed by a newline). The starter opens the stream asoutand provides the loopfor (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
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.