In question Using C ++ filestreams (fstream), how can you determine the file size? , the best answer is the following C ++ snippet:
ifstream file("example.txt", ios::binary | ios::ate); return file.tellg();
By running it myself, I noticed that the size of arbitrarily large files can be determined instantly and with a single read operation.
I usually assumed that to determine the size of the file, you would need to move it byte by byte, adding it to the byte counter. How is this achieved instead? Metadata?
File size is embedded in file metadata in the file system. Different file systems have different ways of storing this information.
. , . - , , ex3 ntfs, , .
. GI Joe , stat posix:
stat (3) manpage
struct stat statbuf; stat("filename.txt", &statbuf); printf("The file is %d bytes long\n", statbuf.st_size);
ios::ate , , .
ios::ate
tellg . ios::binary.
tellg
ios::binary
, , , , ( ). , , - , .
, , fooobar.com/questions/368313/....