fstream seekg(), seekp(), and write()
I'm looking for some clarification on how seekg() and seekp() works with respect to when you are writing to a file. Say for instance I had a file like so: offset 0: 2 offset 4: 4 offset 8: 6 offset 12: 8 offset 16: 10 Now I want to open the file and do some seeks to read and write values. fstream file; file.open("file.txt", fstream::in |fstream::out | fstream::binary); file.seekp(0, ios::end) // seek to the end of the file int eofOffset = file.tellp(); // store the offset of the end-of-file, in this case 20 int key = 0; file.seekg(12, ios::beg); // set the seek cursor to offset 12 from the