讀寫配置檔案教程

2021-08-20 04:28:52 字數 623 閱讀 6856

配置檔案名為:config.ini

配置檔案格式為:

[config]

serverip = "192.168.1.1"

讀配置檔案

tchar tspath[128] = "";

char srecvip[32] = "";

cstring strpash;

::getcurrentdirectory(128,tspath);

strcat(tspath,"\\config.ini");

if(getfileattributes(tspath) == -1)

return -1;

if(getprivateprofilestring(_t("config"),_t("serverip"),null,srecvip,32,tspath) != 0)

else

return 1;

寫配置檔案:

注釋:uint getprivateprofileint(

int ndefault,       // 如果沒有找到指定的資料返回,則把個變數值賦給返回值

lpctstr lpfilename  // ini檔案的絕對路徑

);

讀寫配置檔案

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 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,s...