VC中读写INI文件
在VC2015中读写INI文件,文件以ANSI格式保存,如果以UTF-8保存,可能会产生乱码。
LPCTSTRstrfile=_T(".//config.ini");TCHARvalue[255]={0};//读键值GetPrivateProfileString(_T("ui"),_T("button1"),_T("default"),value,200,strfile);//写键值对WritePrivateProfileString(_T("UI"),_T("button1"),_T("启动"),strfile);//读整数intleft=GetPrivateProfileInt(_T("UI"),_T("left"),0,strfile);CStringstrleft;strleft.Format(_T("%d"),left);//读出某节的所有键值对TCHARchSection[1000];GetPrivateProfileSection(_T("UI"),chSection,200,strfile);CStringArraylist;intlen;TCHAR*pBuf=chSection;while((len=wcslen(pBuf))>0){list.Add(pBuf);pBuf+=len+1;}//读出某节的所有键名TCHARchSectionName[1000];GetPrivateProfileSectionNames(chSectionName,200,strfile);CStringArraylist1;intlen1;TCHAR*pBuf1=chSectionName;while((len1=wcslen(pBuf1))>0){list1.Add(pBuf1);pBuf1+=len1+1;}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。