c++ - tellg() 函数给出错误的文件大小? - 堆栈溢出

PHOTO EMBED

Mon Mar 21 2022 10:14:52 GMT+0000 (Coordinated Universal Time)

Saved by @jay #c++

#include <limits>

file.ignore( std::numeric_limits<std::streamsize>::max() );
std::streamsize length = file.gcount();
file.clear();   //  Since ignore will have set eof.
file.seekg( 0, std::ios_base::beg );
content_copyCOPY

https://stackoverflow.com/questions/22984956/tellg-function-give-wrong-size-of-file