易截截图软件、单文件、免安装、纯绿色、仅160KB

C/C++多种方法获取文件大小

#include <iostream>
#include <io.h>
#include <sys\stat.h>
#include <afx.h>
#define _AFXDLL
using namespace std;
void main()
{
    // 此文件在工程打开状态下为不可访问
    char* filepath = "..\\test.ncb";
    // 方法一
    struct _stat info;
    _stat(filepath, &info);
    int size = info.st_size;
    cout<<size<<endl;
    // 方法二
    FILE* file = fopen(filepath, "rb");
    if (file)
    {
        int size = filelength(fileno(file));
        cout<<size<<endl;
        fclose(file);
    }
    // 方法三
    CFile cfile;
    if (cfile.Open(filepath, CFile::modeRead))
    {
        int size = cfile.GetLength();
        cout<<size<<endl;
    }
    // 方法四
    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;
        Close


相关文档:

航空公司管理系统(VC++ 与SQL 2005)

系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
      这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......

C/C++软件工程师就业求职手册节选二

 5、#define宏定义。宏只是简单的文本替换,很容易引起歧义。
#include <stdio.h>
#define CONS(a,b) (int)(a##e##b)
#define STR(s) #s
int main()
{
   printf(STR(vck));
   printf("\n");
   printf("%d\n",CONS(2,3));
   return 0; ......

C/C++——小编谈C语言函数那些事(14)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.       normvideo函数
 
malloc函数的功能是选择正常亮度字符,其用法为:void normvideo(void);程序实例如下:
#include < ......

C判断文件存在

 用函数access,头文件是io.h,原型:
  
int   access(const   char   *filename,   int   amode);
amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。
这个函数还可以检查其它文件属性:
06   &nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号