Print a File
easyQuestion 580Write 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, so 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.