设为首页 加入收藏

TOP

VC使用tinyxml读写INI,cfg,XML配置文件
2014-11-23 20:10:58 】 浏览:312
Tags:使用 tinyxml 读写 INI cfg XML 配置 文件
#define UPDATE_CONFIG "update.cfg" //客户端版本信息文件
//解析Update.cfg文件
TiXmlDocument UpdateCfgDoc(UPDATE_CONFIG);
if (!UpdateCfgDoc.LoadFile())
{
::MessageBox(NULL, "读取客户端版本文件失败!", NULL, MB_ICONERROR);
SwitchStateAsync(US_UpdateFailed);
return 0;
}
TiXmlElement* pConfigRoot = UpdateCfgDoc.RootElement()->FirstChildElement();
if (NULL == pConfigRoot)
{
return 0;
}
const char* szCurVer = pConfigRoot->Attribute("ClientVersion");
const char* szCurToolVer = pConfigRoot->Attribute("UpdateToolVersion");


//保存玩家当前选择服务器到配置文件
#define SERVER_CONFIG "LoginServer.cfg" //保存玩家选择的区
TiXmlDocument ServerConfigDoc(SERVER_CONFIG);
if (!ServerConfigDoc.LoadFile())
{
::MessageBox(NULL, "解析本地服务器选择配置文件失败!", NULL, MB_ICONERROR);
return;
}
CString strLoginServerName;
m_CurLoginServer.GetWindowText(strLoginServerName);
TiXmlElement* pHistoryServer = ServerConfigDoc.RootElement()->FirstChildElement();
if(pHistoryServer!=NULL)
{
if(strcmp(pHistoryServer->Value(), "server") == 0)
pHistoryServer->SetAttribute("name", strLoginServerName);
ServerConfigDoc.SaveFile();
}
else
{
TiXmlElement ele("server");
ele.SetAttribute("name",strLoginServerName);
ServerConfigDoc.RootElement()->LinkEndChild(&ele);
ServerConfigDoc.SaveFile();
}


摘自 破空的专栏
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VC2005 GDI+编程--图像处理之Draw.. 下一篇VC++ GDI画立体管道

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目