← Back to Streams
Question 655
Reuse One fstream Object
Reuse One fstream Object
The program below opensdata.txtfor writing with anfstream, writes the number42, and later reads a number back from the same stream object. Complete it so that, between the write and the read, it: 1. closes the stream withf.close(), 2. reopens the same file on the same object withf.open("data.txt", ios::in). The read and the final print are already written. The program must print exactly the output shown in Expected Output.
Expected Output:
42= 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.