CJCoding With Joseph
15free / daySign inCreate account

The program below opens data.txt for writing with an fstream, writes the number 42, 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 with f.close(), 2. reopens the same file on the same object with f.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, so print one after the last line.

Hints2 available
Topics
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.