← Back to Streams
Question 585
Number Each Line
Number Each Line
Write a function void printNumbered(const string& filename) that prints every line of the file preceded by its 1-based line number, a colon and one space. For a file containing:
milk
eggs
the function prints exactly the output shown in Expected Output.
Each output line ends with a newline.
Do NOT write a main function.Expected Output:
1: milk 2: eggs 1: open door 2: walk in 3: sit down
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsifstream
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.