|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Files in MFC
In the Microsoft Foundation Class Library (MFC), class CFile handles normal file I/O operations. This family of articles explains how to open and close files as well as read and write data to those files. It also discusses file status operations. For a description of how to use the object-based serialization features of MFC as an alternative way of reading and writing data in files, see the article Serialization.
Note When you use MFC CDocument objects, the framework does much of the serialization work for you. In particular, the framework creates and uses the CFile object. You only have to write code in your override of the Serialize member function of class CDocument.
The CFile class provides an interface for general-purpose binary file operations. The CStdioFile and CMemFile classes derived from CFile and the CSharedFile class derived from CMemFile supply more specialized file services.
For more information about alternatives to MFC file handling, see File Handling in the Run-Time Library Reference and File I/O in the Platform SDK.
For information about derived CFile classes, see the MFC hierarchy chart.
What do you want to do?
- Open a file with CFile
- Read and write a file with CFile
- Close a file with CFile
- Access file status with CFile
Use MFC Serialization (Object Persistence)
- Create a serializable class
- Serialize an object via a CArchive object
- Create a CArchive object
- Use CArchive << and >> operators
- Store and load CObjects and CObject-derived objects via an archive