← Back to Streams
Question 580
Print a File
Print a File
Write a functionvoid printFile(const string& filename)that prints every line of the file tocout, in order, each followed by a newline. If the file contains: red green the function prints exactly the output shown in Expected Output. The starter opens the file and declaresstring line; write thewhile (getline(in, line))loop that prints each line. Do not print anything extra before or after the lines. Do NOT write a main function.
Expected Output:
red green one two three
= newline. The output ends with a newline — print one after the last line.
Hints2 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.