C++获取文件大小
来源:互联网 发布:源码免费下载 编辑:程序博客网 时间:2024/06/05 04:48
#include < iostream>
#include < io.h>
#include < sys\stat.h>
#include < afx.h>
#define _AFXDLL
using namespace std;
void main()
{
// 此文件在工程打开状态下为不可访问
char* filepath = "..\\test.ncb";
// C++获取文件大小方法一
struct _stat info;
_stat(filepath, &info);
int size = info.st_size;
cout< < size< < endl;
// C++获取文件大小方法二
FILE* file = fopen(filepath, "rb");
if (file)
{
int size = filelength(fileno(file));
cout< < size< < endl;
fclose(file);
}
// C++获取文件大小方法三
CFile cfile;
if (cfile.Open(filepath, CFile::modeRead))
{
int size = cfile.GetLength();
cout< < size< < endl;
}
// C++获取文件大小方法四
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);
}
}
C++获取文件大小方法五,这种方法不需要打开文件就能直接获取到文件大小
CFile cfile;
CFileStatus rStatus;
CFile::GetStatus(_T("D:\\Program Files\\360\\360SD\\360hips.exe"),rStatus);
ULONGLONG ulong = rStatus.m_size;
#include < io.h>
#include < sys\stat.h>
#include < afx.h>
#define _AFXDLL
using namespace std;
void main()
{
// 此文件在工程打开状态下为不可访问
char* filepath = "..\\test.ncb";
// C++获取文件大小方法一
struct _stat info;
_stat(filepath, &info);
int size = info.st_size;
cout< < size< < endl;
// C++获取文件大小方法二
FILE* file = fopen(filepath, "rb");
if (file)
{
int size = filelength(fileno(file));
cout< < size< < endl;
fclose(file);
}
// C++获取文件大小方法三
CFile cfile;
if (cfile.Open(filepath, CFile::modeRead))
{
int size = cfile.GetLength();
cout< < size< < endl;
}
// C++获取文件大小方法四
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);
}
}
C++获取文件大小方法五,这种方法不需要打开文件就能直接获取到文件大小
CFile cfile;
CFileStatus rStatus;
CFile::GetStatus(_T("D:\\Program Files\\360\\360SD\\360hips.exe"),rStatus);
ULONGLONG ulong = rStatus.m_size;
0 0
- C/C++ 获取文件大小
- linux获取文件大小[c]
- c获取文件大小
- c语言文件大小获取
- C语言获取文件大小
- LINUX C获取文件大小
- C语言获取文件大小
- C语言获取文件大小
- LINUX C获取文件大小
- C语言获取文件大小
- LINUX C获取文件大小
- C语言获取文件大小
- c 获取文件大小
- linux c获取文件大小
- C语言获取文件大小
- c语言获取文件大小
- C语言获取文件大小
- linux c 获取文件大小
- MFC 获得各类指针、句柄的方法
- 开源企业IM-免费企业即时通讯-ENTBOOST V0.9版本发布
- 也来晒晒的我的学习成绩
- GWT-Bootstrap3中 组件开发文档(一)
- 【实践驱动开发3-006】TI WL1835MODCOM8 在android的移植 - SDIO wifi驱动的注册步骤
- C++获取文件大小
- hd 2034 人见人爱A-B
- 中科燕园arcgis外包案例---现代城三维物业可视化系统
- Qt 在Windows下的安装于配置
- work_weipa_隐藏滚动条
- 判断两个二叉树是否结构相同
- QT x264
- 判断二叉树是不是AVL平衡树
- 简要高效vim配置文件 .vimrc