需要这么几个库,直接放在你的代码工程里即可:
#include "rapidxml.h"
#include "rapidxml_utils.h"
int ReBornBossConf::loadConf(const char* szFileName){ rapidxml::file<char> fdoc(szFileName); rapidxml::xml_document<char> doc; doc.parse<0>(fdoc.data()); //! 获取根节点 rapidxml::xml_node<>* root = doc.first_node(); //活动开启结束配置 rapidxml::xml_node<>* pXmlRoot = root->first_node(); rapidxml::xml_node<>* pXmlNode = pXmlRoot->first_node(); attack_start_day = atoi(pXmlNode->first_attribute("attack_start_day")->value()); attack_start_hour = atoi(pXmlNode->first_attribute("attack_start_hour")->value()); attack_end_day = atoi(pXmlNode->first_attribute("attack_end_day")->value()); attack_end_hour = atoi(pXmlNode->first_attribute("attack_end_hour")->value()); auction_end_day = atoi(pXmlNode->first_attribute("auction_end_day")->value()); auction_end_hour = atoi(pXmlNode->first_attribute("auction_end_hour")->value()); freetimes = atoi(pXmlNode->first_attribute("freetimes")->value()); freecd = atoi(pXmlNode->first_attribute("freecd")->value()); //boss属性配置 pXmlNode = pXmlRoot->next_sibling(); for (rapidxml::xml_node<>* pChildNode = pXmlNode->first_node(); pChildNode != NULL; pChildNode = pChildNode->next_sibling()) { BossAttrsConf bac; uint32_t starid=0; uint32_t starnum=0; bac.groupid= atoi(pChildNode->first_attribute("groupid")->value()); bac.npcid= atoi(pChildNode->first_attribute("npcid")->value()); starid = atoi(pChildNode->first_attribute("aid")->value()); starnum = atoi(pChildNode->first_attribute("anum")->value()); bac.conditions.insert(std::make_pair(starid,starnum)); this->bossAttrs.insert(std::make_pair(bac.groupid,bac)); } pXmlNode = pXmlNode->next_sibling(); for (rapidxml::xml_node<>* pChildNode = pXmlNode->first_node(); pChildNode != NULL; pChildNode = pChildNode->next_sibling()) { AuctionGoodsConf agc; agc.itemid= atoi(pChildNode->first_attribute("itemid")->value()); agc.startprice= atoi(pChildNode->first_attribute("startprice")->value()); agc.addstep = atoi(pChildNode->first_attribute("addstep")->value()); this->auctionGoods.insert(std::make_pair(agc.itemid,agc)); } return 0; }原文链接:https://www.f2er.com/xml/297896.html