int GetBinaryFileSize(void)
{
FILE* pFile; //文件指针
string strFilePath = "E:\\临时文件2\\test_01.bin";
if (0 != fopen_s(&pFile,strFilePath.c_str(),"rb+")) // 打开一个二进制文件
{
return -1;
}
int nSize = 0;
if(NULL!=pFile)
{
fseek(pFile,0,SEEK_END);
nSize = ftell(pFile);
fclose(pFile);
pFile = NULL ;
}
return nSize;
}
函数: int fseek(FILE *stream, long int offset, int whence);
是stdio中的库函数,功能为设定文件指针的位置。
参数stream:需要读取的文件流;
参数whence:文件源指针的位置,值可以是这三个中的一个:
SEEK_SET、SEEK_CUR、SEEK_END分别表示开头位置,当前位置,结尾位置。
offset:表示whence为基点的偏移量大小。
返回值:成功返回0,失败返回非零。
函数long int ftell(FILE *stream);
stdio中的库函数,获取功能为当前文件读写的位置;
返回值是当前读写位置偏离文件头部的字节数。