我有一些 C++ 代码来查找 xml 和打印中的差异,使用 map 重命名节点标签。这是完整的代码:
#include "pugi/pugixml.hpp"
#include <iostream>
#include <string>
#include <map>
int main()
{
// Define mappings, default left - map on the right
const std::map<std::string, std::string> tagmaps
{
{"id", "id"}, {"description", "content"}
};
pugi::xml_document doca, docb;
pugi::xml_node found, n;
std::map<std::string, pugi::xml_node> mapa, mapb;
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("data").children("entry")) {
const char* id = node.child_value("id");
mapa[id] = node;
}
for (auto& node: docb.child("data").children("entry")) {
const char* idcs = node.child_value("id");
if (!mapa.erase(idcs)) {
mapb[idcs] = node;
}
}
for (auto& ea: mapa) {
std::cout << "Removed:" << std::endl;
ea.second.print(std::cout);
// CURL to remove entries from ES
}
for (auto& eb: mapb) {
// change node name if mapping found
found = tagmaps.find(n.name());
if((found != tagmaps.end()) {
n.set_name(found->second.c_str());
}
}
}
这是我尝试编译时遇到的错误。我是 C++ 的新手,我很难修复它。任何帮助或输入将不胜感激。
src/main.cpp:49:8: error: no viable overloaded '='
found = tagmaps.find(n.name());
最佳答案
那是因为你分配给了错误的类型:
found = tagmaps.find(n.name());
std::map<K,V>::find const
返回 std::map<K,V>::const_iterator
, pugi::xml_node
没有赋值运算符在右手边需要这样的东西。
你需要制作found
正确的类型:
std::map<std::string, std::string>::const_iterator found = tagmaps.find(n.name());
或者,如果是 C++11,强烈首选:
auto found = tagmaps.find(n.name());
事实上,查看 xml_node
的引用资料,我没有看到任何 operator=
完全...
关于c++ - 在 C++ 程序上没有可行的重载 '=',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730796/