这是我的代码,用于比较XML文件,使用映射将xml标记名称定义为内容。'mapped_type'没有可行的转换
#include "pugi/pugixml.hpp"
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
pugi::xml_document doca, docb;
std::map<std::string, pugi::xml_node> mapa, mapb;
std::map<int, std::string> tagMap {make_pair(1, "data"), make_pair(2, "entry"), make_pair(3, "id"), make_pair(4, "content")};
if (!doca.load_file("a.xml") || !docb.load_file("b.xml")) {
std::cout << "Can't find input files";
return 1;
}
for (auto& node: doca.child(tagMap[1]).children(tagMap[2])) {
auto id = node.child_value(tagMap[3]);
mapa[id] = node;
}
for (auto& node: docb.child(tagMap[1]).children(tagMap[2])) {
auto idcs = node.child_value(tagMap[3]);
if (!mapa.erase(idcs)) {
mapb[idcs] = node;
}
}
}
我得到的错误是这样的:
src/main.cpp:20:30: error: no viable conversion from 'mapped_type' (aka 'std::__1::basic_string<char>') to
'const char_t *' (aka 'const char *')
for (auto& node: doca.child(tagMap[1]).children(tagMap[2])) {
^~~~~~~~~
关于建议我尝试这样的做法:
auto id = node.child_value(tagMap[3].c_str());
但我仍然得到同样的错误。看起来我试图使用地图来定义标记名称已经导致了很多问题,只是硬编码它,但映射它似乎是合乎逻辑的,因为将来我会将地图移动到一个外部文件,所以我可以运行该程序的不同XML标签,无需每次重新编译。
请查看它显示错误的位置....以及您实际更改代码的位置。 – Nawaz
只是一个猜测:'const的自动&' –
@DieterLücking'''const的自动ID = node.child_value(tagMap [3] .c_str());'''喜欢这个?我得到相同的错误 –