← Back to Streams
Question 598
Write One Line
Write One Line
Write a functionvoid writeGreeting(const string& filename)that opensfilenamewith anofstream(the starter does this asout) and writes exactly one line:Hello, file!followed by a newline. Nothing else may be written. The test calls your function, then 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:
Hello, file! Hello, file!
= 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.