VC中讀寫INI檔案

2021-09-20 20:37:39 字數 1017 閱讀 1537

在vc2015中讀寫ini檔案,檔案以ansi格式儲存,如果以utf-8儲存,可能會產生亂碼。

lpctstr  strfile = _t(".");

tchar value[255] = ;

//讀鍵值

getprivateprofilestring(

_t("ui"),

_t("button1"), 

_t("default"),

value,

200,

strfile);

//寫鍵值對

writeprivateprofilestring(_t("ui"), _t("button1"), _t("啟動"), strfile);

//讀整數

int left = getprivateprofileint(_t("ui"), _t("left"), 0, strfile);

cstring strleft;

strleft.format(_t("%d"),left);

//讀出某節的所有鍵值對

tchar  chsection[1000];

getprivateprofilesection(_t("ui"), chsection, 200, strfile);

cstringarray list;

int len;

tchar *pbuf = chsection;

while ((len = wcslen(pbuf)) > 0)

//讀出某節的所有鍵名

tchar  chsectionname[1000];

getprivateprofilesectionnames(chsectionname, 200, strfile);

cstringarray list1;

int len1;

tchar *pbuf1 = chsectionname;

while ((len1 = wcslen(pbuf1)) > 0)

VC中讀寫ini檔案

strtempa.getbuffer max path max path,c usefile usefile.ini file 使用strtempa中的內容.補充四點 1.ini檔案的路徑必須完整,檔名前面的各級目錄必須存在,否則寫入不成功,該函式返回 false 值.2.檔名的路徑中必須為 因為在...

VC讀寫INI檔案

在我們寫的程式當中,總有一些配置資訊需要儲存下來,以便完成程式的功能,最簡單的辦法就是將這些資訊寫入ini檔案中,程式初始化時再讀入.具體應用如下 一.將資訊寫入.ini檔案中.1.所用的winapi函式原型為 其中各引數的意義 lpctstr lpstring 是鍵值,也就是變數的值,不過必須為l...

VC讀寫INI檔案

在我們寫的程式當中,總有一些配置資訊需要儲存下來,以便完成程式的功能,最簡單的辦法就是將這些資訊寫入ini檔案中,程式初始化時再讀入.具體應用如下 一.將資訊寫入.ini檔案中.1.所用的winapi函式原型為 其中各引數的意義 lpctstr lpstring 是鍵值,也就是變數的值,不過必須為l...