1) seekg method actually moves the file pointer. The g stands for “get” so it moves the get pointer. It takes two arguments. The first parameter is an offset that determines how many bytes to move the file pointer. The second parameter is an ios flag that specifies what the offset parameter should be offset from.
2) tellg() get the position of the get pointer and tellp() gets the position of the put pointer. So tellg() is the place where you read in the file.
Given that knowledge, I have the following line of code:
iofile.seekg(iofile.tellg(), ios::beg); // seek to current file position
This understand what is going on. The first thing the compiler does it is call iofile.tellg(). This returns the number of bytes from the beginning of the file that the get pointer is at. In other words, it tells you how many characters into the file the pointer is currently at. The ios::beg is a flag passed to seekg that tells seekg where to move the pointer - in this case we move it to the beginning of the file. Hence, what this expression does is moves the pointer to the beginning of the file and then offsets the pointer n bytes where n is the number of bytes that tellg returns. In other words, it seems to be moving the pointer in the same exact position it started at! So what is the point of this expression? Am I missing something?