Freigeben über


CFile Class

The base class for Microsoft Foundation Class file classes.

class CFile : public CObject

Members

Public Constructors

Name

Description

CFile::CFile

Constructs a CFile object from a path or file handle.

Public Methods

Name

Description

CFile::Abort

Closes a file ignoring all warnings and errors.

CFile::Close

Closes a file and deletes the object.

CFile::Duplicate

Constructs a duplicate object based on this file.

CFile::Flush

Flushes any data yet to be written.

CFile::GetFileName

Retrieves the filename of the selected file.

CFile::GetFilePath

Retrieves the full file path of the selected file.

CFile::GetFileTitle

Retrieves the title of the selected file.

CFile::GetLength

Retrieves the length of the file.

CFile::GetPosition

Retrieves the current file pointer.

CFile::GetStatus

Retrieves the status of the open file, or in the static version, retrieves the status of the specified file (static, virtual function).

CFile::LockRange

Locks a range of bytes in a file.

CFile::Open

Safely opens a file with an error-testing option.

CFile::Read

Reads (unbuffered) data from a file at the current file position.

CFile::Remove

Deletes the specified file (static function).

CFile::Rename

Renames the specified file (static function).

CFile::Seek

Positions the current file pointer.

CFile::SeekToBegin

Positions the current file pointer at the beginning of the file.

CFile::SeekToEnd

Positions the current file pointer at the end of the file.

CFile::SetFilePath

Sets the full file path of the selected file.

CFile::SetLength

Changes the length of the file.

CFile::SetStatus

Sets the status of the specified file (static, virtual function).

CFile::UnlockRange

Unlocks a range of bytes in a file.

CFile::Write

Writes (unbuffered) data in a file to the current file position.

Public Operators

Name

Description

CFile::operator HANDLE

A handle to a CFile object.

Public Data Members

Name

Description

CFile::hFileNull

Determines if the CFile object has a valid handle.

CFile::m_hFile

Usually contains the operating-system file handle.

Protected Data Members

Name

Description

CFile::m_pTM

Pointer to CAtlTransactionManager object.

Remarks

It directly provides unbuffered, binary disk input/output services, and it indirectly supports text files and memory files through its derived classes. CFile works in conjunction with the CArchive class to support serialization of Microsoft Foundation Class objects.

The hierarchical relationship between this class and its derived classes allows your program to operate on all file objects through the polymorphic CFile interface. A memory file, for example, behaves like a disk file.

Use CFile and its derived classes for general-purpose disk I/O. Use ofstream or other Microsoft iostream classes for formatted text sent to a disk file.

Normally, a disk file is opened automatically on CFile construction and closed on destruction. Static member functions permit you to interrogate a file's status without opening the file.

For more information on using CFile, see the articles Files in MFC and File Handling in the Run-Time Library Reference.

Inheritance Hierarchy

CObject

CFile

Requirements

Header: afx.h

See Also

Reference

CObject Class

Hierarchy Chart

CStdioFile Class

CMemFile Class

Concepts

MFC Sample DRAWCLI

Other Resources

How Do I: Use the CFile Class?