vc中操作INI檔案函式

2021-07-05 18:26:23 字數 2911 閱讀 8114

一 vc中操作ini檔案函式

函式名功能

備註getprivateprofileint                      

讀取ini檔案指定塊中的鍵名對應的整數值。

getprivateprofilesection

讀取ini檔案指定塊中的所有鍵名及其對應值。

getprivateprofilesectionnames

讀取一ini檔案中所有的塊名。

getprivateprofilestring

讀取ini檔案指定塊中的鍵名對應的字串。

getprivateprofilestruct

讀取ini檔案指定塊中的鍵名對應的資料

getprofileint

讀取win.ini中指定塊中的鍵名對應的整數值。

getprofilesection

讀取win.ini中指定塊中所有的鍵名及其值。

getprofilestring

讀取win.ini中指定塊中的鍵名的對應值。

writeprivateprofilesection

替換ini檔案中指定塊中所有鍵名對應的值。

writeprivateprofilestring

把給定的鍵名及其值寫入到指定ini檔案的相應塊中。

writeprivateprofilestruct

把指定的鍵名及其資料寫入到指定ini檔案的塊中。

writeprofilesection

替換win.ini中指定塊的所有鍵名對應的值。

writeprofilestring

將給定的鍵名及值寫入win.ini中對應的塊中。

二  使用案例

1)函式getprivateprofilesectionnames用於讀取ini檔案中所有快名

getprivateprofilesectionnames(sectionname, allsections, m_strpath.c_str());

2)函式getprivateprofilesection讀取ini檔案指定塊中所有鍵名及其對應的值

getprivateprofilesection(sectiontemp.strfulname.c_str(), pstrsectionchiefkey, sectionlen, m_strpath.c_str());

vectorvcttypenametemp;

vectorvctallscttemp;

char sectionname[allsections];

memset(sectionname,0,allsections);

string strsectionname="";

getprivateprofilesectionnames(sectionname, allsections, m_strpath.c_str());

chartostring(strsectionname,sectionname,allsections);

char *ponesectionname = &strsectionname[0];

int ii = strlen(ponesectionname); //多於。。。

int isectionnamechieflen = 0;

while(0 != *ponesectionname)

else

char pstrsectionchiefkey[sectionlen];

memset(pstrsectionchiefkey,0,sectionlen);

getprivateprofilesection(sectiontemp.strfulname.c_str(), pstrsectionchiefkey, sectionlen, m_strpath.c_str());

string strsectionchiefkey = "";

chartostring(strsectionchiefkey, pstrsectionchiefkey, sectionlen);

char* pkey= &strsectionchiefkey[0];

int iallkeylen = 0;

bool bconfig = false;

bool bsect = true;

while(0 != *pkey)

sectionskey.strkeyname = strkey.substr(0,iequal);

sectionskey.strkeyvalue = strkey.substr(iequal + 1);

sectionskey.strkey = strkey;

pkey = &strsectionchiefkey[iallkeylen];

sectiontemp.vctsectkey.push_back(sectionskey);

if(order == sectionskey.strkeyname) //設定行值

if(uposition == sectionskey.strkeyname)

sectiontemp.regnumber = regiontemp;

bconfig = true;

}} if(false == bsect)

if(false == bconfig && sectiontemp.strposname.empty())

ponesectionname = &strsectionname[isectionnamechieflen];

vctallscttemp.push_back(sectiontemp);

} classifysortsection(mapallsct, vcttypenametemp, vctallscttemp);

vctallscttemp.clear();

vcttypenametemp.clear();

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檔案

原文http www.cnblogs.com boneking archive 2008 11 04 1326221.html 三.迴圈寫入多個值,設現有一程式,要將最近使用的幾個檔名儲存下來,具體程式如下 1.寫入 cstring strtemp,strtempa int i int ncount...