VC++读写配置文件.ini

1.首先.ini文件的编码形式必须是Unicode,可通过文件另存为修改;

2.获取配置文件路径(注:我是放在.exe执行文件的根目录下的)

CString   sPath;  
CString StrName;
StrName="dasdasda";
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);   
sPath.ReleaseBuffer();  //到这一步获取的是执行文件(.exe)的路径 
int   nPos;   
nPos=sPath.ReverseFind('\\');   
sPath=sPath.Left(nPos);   
CString   lpszFile=sPath+"\\uilib.ini";//这里是配置文件路径

3.写入配置文件(若配置文件中已存在cityname,则会覆盖它所对应的值)

WritePrivateProfileString(CString("AttenCitys"),CString("cityname"),StrName,lpszFile);

 

4.读取配置文件

CString str;
GetPrivateProfileString(CString("AttenCitys"),CString("cityname"),CString("NULL"),str.GetBuffer(),MAX_PATH,lpszFile);
str.ReleaseBuffer();

 

 

 

 

posted @ 2013-07-17 12:54  偶不是大叔  阅读(3166)  评论(0编辑  收藏  举报