Sid M. answered 02/24/20
Studied Computer Science and Engineering at University of Washington
Hello, Ethan,
Rather than provide the answer, I'll help you figure it out. The statements which drive the answer are:
These statements affect which character will be read by the last statement, above, the `train.get(ch)`. Note that, since the `train` stream has been opened for both input and output, the use of either (or, as in the code here, both) seekp() and seekg(), or tellp() and tellg(), should have the same effect. (The 'p' and 'g' versions are interchangeable, because there's only 1 'cursor' for the file)..
So:
- `train.seekp(10, ios::beg)` sets the file cursor to 10 (from the beginning).
- `train.seekg(-2, ios::cur)` sets the file cursor to 2 before its current location (i.e. 10 - 2), or 8.
- `train.seekp(10 + train.tellg() - 3)` sets the file cursor to position 10 + the current location - 3 (i.e. 10 + 8 - 3), or 15.
- Finally, `train.get(c)` reads the character at location 15, and leaves the cursor at location 16.