讀寫配置檔案

2021-08-01 21:37:41 字數 1705 閱讀 9556

// 寫配置檔案

#include

#include

#include

#include

using

std::cout;

using

std::endl;

int main()

; int nlen = strlen("d:\\myinifile.ini"); // 16

nlen = strlen(lppath); // 0

strcpy_s(lppath, strlen("d:\\myinifile.ini") + 1, "d:\\myinifile.ini");

writeprivateprofilestringa(

"liming",

"***",

"man",

lppath);

writeprivateprofilestringa("liming", "age", "20", lppath);

writeprivateprofilestringa("fangfang", "***", "woman", lppath);

writeprivateprofilestringa("fangfang", "age", "18", lppath);

cout

<< "success"

<< endl;

cout

<< endl;

// 讀取配置檔案

cout

<< "liming personal information."

<< endl;

char ***[20] = ;

getprivateprofilestringa(

"liming", // 應用程式名,節名

"***", // 鍵名

"", // 預設返回值,如果沒有獲取到鍵值

***, // 獲取返回鍵值

6, // 緩衝區大小

lppath); // ini檔案的路徑

cout

<< *** << endl;

int age = 0;

age = getprivateprofileinta(

"liming", // 應用程式名,節名

"age", // 鍵名

0, // 預設返回值,如果沒有獲取到鍵值

lppath); // ini檔案的路徑

cout

<< age << endl;

cout

<< "fangfang personal information."

<< endl;

getprivateprofilestringa("fangfang", "***", "", ***, 6, lppath);

cout

<< *** << endl;

age = 0;

age = getprivateprofileinta("fangfang", "age", 0, lppath);

cout

<< age << endl;

system("pause");

return

0;}

讀寫配置檔案

windows作業系統專門為此提供了6個api函式來對配置設定檔案進行讀 寫 getprivateprofileint 從私有初始化檔案獲取整型數值 getprivateprofilestring 從私有初始化檔案獲取字串型值 getprofileint 從win.ini 獲取整數值 getprof...

讀寫配置檔案

procedure curstepchanged curstep tsetupstep varsetupname string inipath string begin case curstep of ssinstall 複製檔案前 begin end sspostinstall 完成複製 begi...

讀寫配置檔案

配置檔案讀寫系統方法和測試函式 include readconfig.h define cfgname test.txt void mymenu inttgetcfg char value 1024 int vlen 0 printf nplease input key scanf s,name r...