Although two different stream objects are used for reading and writing, the read and write positions
are tightly coupled. seekg() and seekp() call the same member function of the stream buffer.20
Thus, the read position must always be set to the beginning of the file in order for the complete
contents of the file to be written, after which the read/write position is again at the end of the file so
that new lines written are appended.