← Back to Streams
Question 646
fstream in Write Mode
fstream in Write Mode
Write a functionvoid writeWithFstream(const string& filename, const string& text)that opensfilenamewith anfstreaminios::outmode and writestextfollowed by a newline. The test puts old content in the file first, calls your function, then prints every line of the file. ForwriteWithFstream("notes_a.txt", "hello")it prints the output shown in Expected Output. Do NOT write a main function.
Expected Output:
hello fstream works
= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Streamsfstream
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.