VC程式設計基礎 檔案和資料夾操作

2021-05-21 13:05:38 字數 826 閱讀 2677

之前寫關於檔案操作的程式,總要冥想一番,在msdn上或網路上搜尋一番才能知道有哪些操作檔案的api。所以今天閒暇之餘總結下,

以後雖然做不到寫程式是信手拈來,但至少也略有所知啊:

一)createfile,setfilepointer,writefile,getfilesize, readfile,closehandle, copyfile, movefile, deletefile, _trename。為了減少io的操作,在寫檔案的時候我們可以加乙個buffer,只有這個buffer滿了或者放不下內容了才往檔案裡寫,一般情況下只是把內容拷貝到buffer裡,簡單的例子如下:

int writestring(lpctstr strfilename, lpcstr strscr)

::setfilepointer(hfile, 0, null, file_end);

int strlength = ::strlen(strscr);

if(bufpos + strlength > max_length)

memcpy(buffer + bufpos, strscr, strlength);

bufpos += strlength;

closehandle(hfile);

return 0;

}二)fopen, fread,fwrite, fclose,fgetc,fgetc, fgets,fputs, fseek,ftell

三)運用資料流操作檔案:

1.ifstream: 可以用方法getline從該物件中一行行的讀取

2.ofstream:基於該物件的方法:write,flush,put, tellp, seekp.

VC下遍歷資料夾和檔案

一 先介紹乙個結構win32 find data typedef struct win32 find data win32 find data win32 find data ffd handle hfind findfirstfile c ffd 二 函式findfirstfile 1 宣告 ha...

VC遍歷資料夾下所有檔案和資料夾

2010 03 25 16 59 一 先介紹乙個結構win32 find data typedef struct win32 find data win32 find data win32 find data ffd handle hfind findfirstfile c ffd 二 函式find...

VC遍歷資料夾下所有檔案和資料夾

一 先介紹乙個結構win32 find data typedef struct win32 find data win32 find data 可以通過 findfirstfile 函式,根據檔案路徑把待操作檔案的相關屬性讀取到 win32 find data 結構中去 win32 find dat...