Chinaunix首页 | 论坛 | 博客
  • 博客访问: 670027
  • 博文数量: 134
  • 博客积分: 3158
  • 博客等级: 中校
  • 技术积分: 1617
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-30 22:36
文章分类

全部博文(134)

文章存档

2012年(2)

2011年(28)

2010年(68)

2009年(35)

2008年(1)

我的朋友

分类: C/C++

2011-03-31 10:15:17

阅读材料:CFile类常用成员

 

Data Members

Usually contains the operating-system file handle.通常包含操作系统文件句柄

Construction

Constructs a CFile object from a path or file handle.1个文件路径或文件句柄构造1CFile对象

Closes a file and deletes the object.关闭1个文件并删除该文件对象

Safely opens a file with an error-testing option.安全地打开文件(具有错误测试选项)

Input/Output

Reads (unbuffered) data from a file at the current file position.从文件的当前文件位置读数据(非缓冲)

Writes (unbuffered) data in a file to the current file position.将数据写到文件的当前位置(非缓冲)

Position

Positions the current file pointer.改变文件指针的位置

Positions the current file pointer at the beginning of the file.将文件指针移动到文件开始的地方

Positions the current file pointer at the end of the file.将文件指针移动到文件结束的地方

Status

Retrieves the filename of the selected file.获取选定的文件的文件名称

Retrieves the full file path of the selected file.获取选定文件的完整路径(包括目录和文件名)

Retrieves the title of the selected file.获取选定文件的标题

Retrieves the current file pointer.获取当前文件指针的位置

Sets the full file path of the selected file.设置选定文件完整的路径

Static

Deletes the specified file (static function).删除指定的文件(静态函数)

Renames the specified file (static function).修改指定文件的名称(静态函数)

 

class CFile : public CObject

{

public:

// Flag values

       enum OpenFlags {

              modeRead          = (int) 0x00000,

              modeWrite          = (int) 0x00001,

              modeReadWrite = (int) 0x00002,

              shareCompat       = (int) 0x00000,

              shareExclusive    = (int) 0x00010,

              shareDenyWrite = (int) 0x00020,

              shareDenyRead = (int) 0x00030,

              shareDenyNone = (int) 0x00040,

              modeNoInherit    = (int) 0x00080,

              modeCreate        = (int) 0x01000,

              modeNoTruncate = (int) 0x02000,

              typeText              = (int) 0x04000, // typeText and typeBinary are

              typeBinary           = (int) 0x08000, // used in derived classes only

              osNoBuffer         = (int) 0x10000,

              osWriteThrough = (int) 0x20000,

              osRandomAccess= (int) 0x40000,

              osSequentialScan= (int) 0x80000,

              };

 

       enum Attribute {

              normal   =    0x00,

              readOnly=    0x01,

              hidden   =    0x02,

              system =    0x04,

              volume =    0x08,

              directory=     0x10,

              archive =    0x20

              };

 

       enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };

 

// Constructors

       CFile();

       CFile(HANDLE hFile);

       CFile(LPCTSTR lpszFileName, UINT nOpenFlags);    //LPCTSTRC结束符的字符串的指针

 

// Attributes

       HANDLE m_hFile;

 

       virtual ULONGLONG GetPosition() const;

       virtual CString GetFileName() const;

       virtual CString GetFileTitle() const;

       virtual CString GetFilePath() const;

 

// Operations

       virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL);

 

       static void PASCAL Rename(LPCTSTR lpszOldName, LPCTSTR lpszNewName);

       static void PASCAL Remove(LPCTSTR lpszFileName);

 

       ULONGLONG SeekToEnd();

       void SeekToBegin();

 

// Overridables

       virtual CFile* Duplicate() const;

 

       virtual ULONGLONG Seek(LONGLONG lOff, UINT nFrom);

 

       virtual UINT Read(void* lpBuf, UINT nCount);

       virtual void   Write(const void* lpBuf, UINT nCount);

 

       virtual void Close();

 

// Implementation

public:

       virtual ~CFile();

 

protected:

       BOOL    m_bCloseOnDelete;

       CString m_strFileName;

};

阅读(2365) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~