MFC對檔案的操作

2021-04-12 22:24:55 字數 821 閱讀 4553

cfile的派生類cstdiofile提供了對檔案進行流式的操作功能。其中函式void cstdiofile::writestring( lpctstr lpsz )寫入乙個字串,需要給字串lpsz的末尾加上換行標誌」/r/n」;函式bool cstdiofile::readstring(cstring &rstring )從檔案中讀取一行,如果檔案未讀完返回true,否則返回false。

比如:寫入檔案的例子

//建立檔案

cstdiofile file;

file.open("ts.txt",cfile::modecreate|cfile::modewrite);

//寫入檔案

cstring str;

str.format("%s/r/n","hello!i am talkingmute!");

file.seek(0,cfile::end);

file.writestring( str );

//關閉檔案

file.close();

比如:讀檔案的例子

cstring strtext = 「」;

cstring szline = 「」;

//開啟檔案

cstdiofile file;

file.open("ts.txt",cfile::moderead);

//逐行讀取字串

while( file.readstring( szline ) )

messagebox(strtext);

//關閉檔案

file.close();

MFC對檔案操作的支援 CFile 類

cfile類提供了沒有快取的二進位制格式的磁碟檔案輸入輸出功能。建構函式 cfile lpctstr lpszfilename,uint nopenflags lpszfilename 檔名 nopenflags 檔案訪問和共享的方式 經典取值 cfile modecreate cfile mode...

對檔案的操作

win32 shfileoperation 1.將 c test.txt 拷貝到 d shfileopstruct lpsh zeromemory lpsh,sizeof lpsh lpsh.hwnd hwnd desktop lpsh.fflags fof noconfirmation fof p...

對檔案的操作

對檔案的操作大致分為3類 第一類為r 唯讀 當進行唯讀操作時,無法對文字進行更改。注意 當進行r操作時游標會移至最前方從而讀取游標後的內容。第二類為w 只寫 當進行只寫操作時,無法對檔案進行讀取操作。注意 當進行只寫操作時會情況檔案裡的內容。第三類為a 只追加 當進行只追加操作時,無法讀取內容。注意...