其他分享
首页 > 其他分享> > FILE获取文件长度

FILE获取文件长度

作者:互联网

场景

        通过C语言中的File获取文件长度

static std::int64_t GetFileLen(const std::string &strFileName)
{
FILE  *pFile = fopen(strFileName.c_str(), "r");
if (pFile == NULL)
{
return 0;
}
fseek(pFile, 0, SEEK_END);//定位到文件的最后面
std::int64_t  nLen = ftell(pFile);
fclose(pFile);
return nLen;
}

注意:如果打开标志位写成"w+",将会导致nLen返回0,并且文件内容将被清空

标签:std,文件,strFileName,pFile,nLen,获取,FILE,长度
来源: https://blog.51cto.com/fengyuzaitu/2701750