用VC操作INI檔案

2021-04-25 04:34:41 字數 1326 閱讀 2193

原文http://www.cnblogs.com/boneking/archive/2008/11/04/1326221.html

三.迴圈寫入多個值,設現有一程式,要將最近使用的幾個檔名儲存下來,具體程式如下:

1.寫入:

cstring strtemp,strtempa;

int i;

int ncount=6;

file://共有6個檔名需要儲存

for(i=0;i

strtemp.format("%d",ncount);

::writeprivateprofilestring("filecount","count",strtemp,"c://usefile//usefile.ini");

file://將檔案總數寫入,以便讀出.

2.讀出:

ncount=::getprivateprofileint("filecount","count",0,"c://usefile//usefile.ini");

for(i=0;i

補充四點:

1.ini檔案的路徑必須完整,檔名前面的各級目錄必須存在,否則寫入不成功,該函式返回 false 值.

2.檔名的路徑中必須為 // ,因為在vc++中, // 才表示乙個 / .

3.也可將ini檔案放在程式所在目錄,此時 lpfilename 引數為: ".//student.ini".

4.從網頁中貼上源**時,最好先貼上至記事本中,再往vc中貼上,否則易造成編譯錯誤,開始時我也十分不解,好好的**怎麼就不對呢?後來才找到這個方法.還有一些**中使用了全形字符如:<,\等,也會造成編譯錯誤.

對原文的補充:

刪除key

writeprivateprofilestring(

(lpctstr

)strsection,

(lpctstr

)strkey,

null

,         

//      

這裡寫null,

則刪除key (

lpctstr

)m_strpath);

刪除section

writeprivateprofilestring(

(lpctstr

)strsection,

null

,         

//      

這裡都寫

null,

則刪除section

null

,          (

lpctstr

)m_strpath);

VC 操作 ini 檔案

各個函式的作用我就不解釋了,從名字上就可以看出來.也希望大家用的時候如果發現錯誤請指正,可以發mail 給我,miaoxf 126.inifile.h inte ce for the cinifile class.if defined afx inifile h 3ef6d649 6870 480b...

VC操作INI檔案

在我們寫的程式當中,總有一些配置資訊需要儲存下來,以便完成程式的功能,最簡單的辦法就是將這些資訊寫入ini檔案中,程式初始化時再讀入.具體應用如下 一.將資訊寫入.ini檔案中.1.所用的winapi函式原型為 bool writeprivateprofilestring lpctstr lpkey...

VC下的INI檔案操作

在我們寫的程式當中,總有一些配置資訊需要儲存下來,以便完成程式的功能,最簡單的辦法就是將這些資訊寫入ini檔案中,程式初始化時再讀入.具體應用如下 一.將資訊寫入.ini檔案中.1.所用的winapi函式原型為 bool writeprivateprofilestring lpctstr lpkey...