第一种:
#include <string>
using namespace std;
int main()
{
while (0!=fopen_s(&fp,file_address .c_str() ,"rb+"))
{
cout<<"File opened failed"<<endl;
}
//获得文件长度//int fseek( FILE *stream, long offset, int origin );
fseek(fp,0,SEEK_END);
fileLen=ftell(fp);
cout<<"fileLen "<<fileLen<<endl;
}
第二种:
#include <iostream>
#include <string>
#include <fcntl.h>
#include <io.h>
using namespace std;
int main()
{
string filepath="E://22.iso";
FILE* file = fopen(filepath.c_str(), "rb");
if (file)
{
int size = _filelength(fileno(file));
cout<< size<< endl;
fclose(file);
}