CJCoding With Joseph
15free / daySign inCreate account

Print a File

Write a function void printFile(const string& filename) that prints every line of the file to cout, 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 declares string line; write the while (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
Topics:
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.