vc操作常用文件操作(三) CFile Example
CFile is the class used for handling Files in MFC. This class can be used for creating, reading, writing and modifying files. It directly provides unbuffered, binary disk input/output services, and it indirectly supports text files and memory files through its derived classes.
CFile - Creating a File:
There are two ways of creating files. One way is to instantiate the CFile object with the file path. This creates the file. The second way is to call the Open function. This also creates the file.c:\\test\\codersource_cfile_example.txt", CFile::modeCreate|CFile:: modeReadWrite);c:\\test\\codersource_cfile_example.txt", CFile::modeCreate|CFile:: modeReadWrite);
If the file is opened without specifying the mode constant
CFile - Writing to a File:
The function Write is used to write data to the files. The sample code is as follows.
If there is any need to write text line by line, it is better to use the class CStdioFile.
CFile - Reading from a file:
The function Read is used to read data from files. The sample code is,
The function returns the number of bytes read from the file. The maximum number of characters read will be the second parameter of the Read function.
CFile - closing the file:
The Close function is used to close the file. But the close function need not be called, as the destructor will automatically call it if the file is open. So when the object goes out of scope, the destructor calls close function.
from: http://www.codersource.net/mfc_cfile.html
作者:BuildNewApp
出处:http://syxchina.cnblogs.com、 BuildNewApp.com
本文版权归作者、博客园和百度空间共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则作者会诅咒你的。
如果您阅读了我的文章并觉得有价值请点击此处,谢谢您的肯定1。