C++ get file size
作者:互联网
1/
#include <fstream> std::ifstream::pos_type filesize(const char* filename) { std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary); return in.tellg(); }
2/#include <fstream>
int getFileSize(const std::string &fileName)
{
ifstream file(fileName.c_str(), ifstream::in | ifstream::binary);
if(!file.is_open())
{
return -1;
}
file.seekg(0, ios::end);
int fileSize = file.tellg();
file.close();
return fileSize;
}
标签:std,return,ifstream,int,tellg,C++,file,size 来源: https://www.cnblogs.com/jieliujas/p/12220731.html