以下操作需要包含头文件<fstream> | <string>
size_t GetFileSize(const std::string& file_name){
std::ifstream in(file_name.c_str());
in.seekg(0, std::ios::end);
size_t size = in.tellg();
in.close();
return size; //单位是:byte
}
以下操作需要包含头文件<cstdio> | <string>
size_t GetFileSize(const std::string& file_name){
FILE* fp = fopen(file_name.c_str(), "r");
fseek(fp, 0, SEEK_END);
size_t size = ftell(fp);
fclose(fp);
return size; //单位是:byte
}
以下操作需要包含头文件<sys/stat.h> | <string>
size_t GetFileSize(const std::string& file_name){
struct _stat info;
_stat(file_name.c_str(), &info);
size_t size = info.st_size;
return size; //单位是:byte
}
获取文件大小
最新推荐文章于 2023-08-23 15:06:49 发布