第1个回答 推荐于2018-04-04
ifstream file("file");
file.seekg(0, ios::end);
return file.tellg(); //文件大小本回答被网友采纳
第2个回答 2011-06-13
MFC的话,用cfile::SeekToEnd()的返回值。
STL的话,这个是参考代码。用的是ifstream的tellg()方法。
#include <fstream>
#include <iostream>
int main(int argc, char* argv[])
{
std::ifstream ifstr("123");
ifstr.seekg( 0 , std::ios::end );
std::cout<<" file size:"<< ifstr.tellg()<<std::endl;
return 0;
}
第3个回答 2011-06-13
如果是用标准库实现,可以这样。
long size;
FILE *fp;
fp=fopen("file","rb");
fseek(fp,0,SEEK_END);
size=ftell(fp);
flcose(fp);本回答被提问者采纳