c++怎么获取一个文件的大小

2025-06-26 09:47:04
推荐回答(2个)
回答1:

#include
#include
#include
using namespace std;

int main(int argc,char* argv[])
{
string sFileName="c:/aa.txt";
ifstream in(sFileName.c_str());
in.seekg(0,ios::end);
long size = in.tellg();
in.close();
cout<< "文件大小为:"< return 0;
} 这样更准确吧

回答2:

#include
#include
#include
void main()
{
// 此文件在工程打开状态下为不可访问
char* filepath = "D:\\ClassSign.ini"; // 方法一
struct _stat info;
_stat(filepath, &info);
int size = info.st_size;
cout< } //返回的单位是位(bit)