配置檔案的讀寫操作

2021-09-30 06:44:41 字數 1036 閱讀 3321

配置檔案用來記錄登入使用者的設定資訊,使得在下一次登陸時能夠從配置檔案中讀出相應使用者的設定資訊,實現的具體**如下:、

1、先定義個乙個結構體,使用者所有的資訊字段

typedef struct personinfo

personinfo(const personinfo &stpersoninfo)

};2、函式實現向配置檔案中新增訊息記錄

void cinioptdlg::writeuserinfoconfig(personinfo &per)

3、函式實現讀取特定使用者的資訊

void cinioptdlg::readuserinfoconfig(personinfo &per,cstring readname)

{char buf[max_path];

dword size=max_path;

dword readlen=getprivateprofilestring(readname,_t("username"),null,buf,size,configfilepath);

buf[readlen]=0;

per.strusername=buf;

dword readlen2=getprivateprofilestring(readname,_t("usernickname"),null,buf,size,configfilepath);

buf[readlen2]=0;

per.strnickname=buf;

dword readlen3=getprivateprofilestring(readname,_t("useraddress"),null,buf,size,configfilepath);

buf[readlen3]=0;

per.straddress=buf;

dword readlen4=getprivateprofilestring(readname,_t("userphone"),null,buf,size,configfilepath);

buf[readlen4]=0;

per.strphone=buf;

讀寫配置檔案

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