c/c++获取文件大小的方法

#include <iostream>
#include <windows.h>
#include <io.h>
#include <sys\stat.h>using namespace std;void main()
{    char *filepath = "C:\\1.txt";    //方法一    
    HANDLE handle = CreateFile(filepath, FILE_READ_EA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);    if (handle != INVALID_HANDLE_VALUE)
    {        int size = GetFileSize(handle, NULL);
        cout<<size<<endl;
        CloseHandle(handle);
    }     

    //方法二
    WIN32_FIND_DATA fileInfo; 
    HANDLE hFind; 
    DWORD fileSize; 
        hFind = FindFirstFile(filepath ,&fileInfo); 
    if(hFind != INVALID_HANDLE_VALUE) 
        fileSize = fileInfo.nFileSizeLow; 
    cout<<fileSize<<endl;
    FindClose(hFind); 

    //方法三
    FILE* file = fopen(filepath, "r");    if (file)
    {        int size = filelength(fileno(file));
        cout<<size<<endl;
        fclose(file);
    }    //方法四
    struct _stat info;
    _stat(filepath, &info);    int size = info.st_size;
    cout<<size<<endl;    return ;
}

int nRet = _findfirst(str.c_str(),&fd);

网站栏目:c/c++获取文件大小的方法
分享链接:https://www.cdcxhl.com/article12/ihiigc.html

成都网站建设公司_创新互联,为您提供网站收录外贸建站企业建站电子商务自适应网站网站设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设