我们写软件经常会用需要保存用户数据,可以通过配置文件(ini文件)来对数据进行保存。
//写入参数
CString filePath = (".\\configuration.ini");//配置文件路径
CString str; //要写入的字符串
WritePrivateProfileString("参数", "参数1", str, filePath);//将字符串写入到配置文件
//读取参数
CString filePath = (".\\configuration.ini");//要读取的配置文件路径
char buf[100];//用来接收读取字符串的buff
GetPrivateProfileString("参数", "参数1", "err", buf, 100, filePath); //读取字符串
CString str(buf);//将buff(char*)转成CString
if(str=="err")
{
AfxMessgeBox("读取数据失败");
}