第一中方法
// An highlighted block
FILE *fp=fopen("C:\\Windows\\explorer.exe","rb");//打开文件
int size=0;
fseek(fp,0,SEEK_END);//将文件位置指针内置于文件结尾
size=ftell(fp);//得到当前位置与文件开始容位置的字节偏移量。
fclose(fp);//关闭文件
printf("%d",size/1024);//输出结果。
但是这只适用于文件大小不超过2G的情况,如果文件超过2G则不适用这种方法。
第二种方法
// An highlighted block
int main()
{
struct _stat64 st;
_stat64("E:\\1.iso",&st);
cout<<st.st_size;
return 0;
}
当然,这种方法没有文件大小的限制。