<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    weidagang2046的專欄

    物格而后知致
    隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
    數據加載中……

    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.

    CFile cfile_object( "c:\\test\\codersource_cfile_example.txt", CFile::modeCreate|CFile:: modeReadWrite);

    ???? CFile cfile_object;
    ???? cfile_object.Open( "c:\\test\\codersource_cfile_example.txt",? CFile::modeCreate|CFile:: modeReadWrite);
    ???
    ??
    The first parameter to both the functions (CFile() constructor and Open()) is the physical path of the file in the disk.?The second parameter is an enumerated constant. This specifies the mode of opening the file object. The above constants?modeCreate implies "create a new file" and modeReadWrite means "open the file for both reading and writing".

    ?? If the file is opened without specifying the mode constant shareDenyNone, this file can be opened in read mode by?other programs. This feature will be necessary for text files, logs created by programs. For creating text files we use?CFile::typeText and for binary files CFile::typeBinary.

    CFile - Writing to a File:

    ?? The function Write is used to write data to the files. The sample code is as follows.

    ???? CFile cfile_object;
    ???? cfile_object.Open( "c:\\test\\codersource_cfile_example.txt", CFile::modeCreate|CFile::modeWrite);

    ???? char szSampleText[100];
    ???? strcpy(szSampleText, "Sample Text for CFile Write function Example");
    ???? cfile_object.Write (szSampleText,100);?

    ?? 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,

    ???? CFile cfile_object;
    ???? cfile_object.Open( "c:\\test\\codersource_cfile_example.txt", CFile::modeCreate|CFile::modeWrite);

    ???? char szSampleText[100];
    ???? UINT lBytesRead = cfile_object.Read (szSampleText,100);?

    ?? 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

    posted on 2006-08-29 22:53 weidagang2046 閱讀(841) 評論(0)  編輯  收藏 所屬分類: Windows

    主站蜘蛛池模板: 亚洲成人动漫在线观看| 国产黄在线观看免费观看不卡| 日韩免费视频观看| av午夜福利一片免费看久久| 亚洲精品美女久久久久| 国产精品深夜福利免费观看| 在线免费播放一级毛片| 亚洲人成77777在线观看网| 亚洲欧洲久久av| 国产人在线成免费视频| 一边摸一边桶一边脱免费视频| 亚洲欧洲中文日产| 亚洲精品国产va在线观看蜜芽| 1000部拍拍拍18勿入免费视频软件 | 99久久久国产精品免费牛牛四川| 亚洲熟妇丰满xxxxx| 亚洲成av人片在线观看无码不卡| 拨牐拨牐x8免费| 暖暖免费日本在线中文| 色妞www精品视频免费看| 亚洲日本国产精华液| 亚洲日韩国产一区二区三区| 无码国产精品久久一区免费 | 亚洲真人无码永久在线观看| 亚洲五月综合缴情在线观看| 国产精品成人免费一区二区| 日本免费在线中文字幕| 新最免费影视大全在线播放| 中文字幕 亚洲 有码 在线| 亚洲AV无一区二区三区久久| 亚洲国产精品人人做人人爽| 国产一卡2卡3卡4卡2021免费观看| 精品无码一级毛片免费视频观看 | 久久久久se色偷偷亚洲精品av | 久久久久亚洲AV无码网站| 亚洲国产黄在线观看| 日本免费网站在线观看| 野花高清在线观看免费完整版中文 | 亚洲欧洲无码AV不卡在线| 亚洲视频一区在线播放| 亚洲va国产va天堂va久久|