In a scenario using seekg & tellg on a file, I was wondering what is happening under the hood?
// Open file and get file size
int myFileSize;
std::fstream myFile;
myFile.open(myFileName, std::ios::in|std::ios::binary);
if (myFile.is_open())
{
myFile.seekg(0, std::ios::end);
myFileSize = myFile.tellg();
myFile.seekg(0, std::ios::beg);
myFile.close();
}
Q1: Is seekg actually walking the entire contents of the file, until it finds some special "EOF character"? Or does it use some other information provided by the filesystem to "know" where the end of the file is?
Q2: seekg is a stream seeking operation. Does that mean that the entire contents of the file must go through the stream?
Forgive me if I only have an rudimentary understanding of how all this works.