// 方法一
struct _stat info;
_stat(filepath, &info);
int size = info.st_size;
cout<
// 方法二
FILE* file = fopen(filepath, "rb");
if (file)
{
int size = filelength(fileno(file));
cout< fclose(file);
}
// 方法三
CFile cfile;
if (cfile.Open(filepath, CFile::modeRead))
{
int size = cfile.GetLength();
cout< }
// 方法四
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< CloseHandle(handle);
}
//方法五
long getfilesize(const char * filename)
{
FILE *fp;
long lRet;
if ((fp = fopen(filename, "r")) == NULL)
return 0;
fseek(fp, 0, SEEK_END);
lRet = ftell(fp);
fclose(fp);
return lRet;
}
阅读(622) | 评论(0) | 转发(0) |