快速获取文件大小

功能简单,直接上代码

unsigned long getFileSize(FILE* fp)
{
    unsigned long cur_pos = ftell(fp);
    fseek(fp, 0, SEEK_END);
    unsigned long len = ftell(fp);
    fseek(fp, cur_pos, SEEK_SET);

    return len;
}

为了确保文件指针不被改变,

最后的fseek是必不可少的。

posted on 2015-11-19 09:36  修身  阅读(436)  评论(0编辑  收藏  举报

导航