我是 C++ 的新手,在我的程序中获得了一些帮助来比较两个 XML 文件。这是我的代码:
#include "pugixml.hpp"
#include <iostream>
#include <unordered_map>
int main() {
pugi::xml_document doca, docb;
std::map<string, pugi::xml_node> mapa, mapb;
if (!doca.load_file("a.xml") || !docb.load_file("b.xml"))
return 1;
for (auto& node: doca.child("site_entries").children("entry")) {
const char* id = node.child_value("id");
mapa[new std::string(id, strlen(id))] = node;
}
for (auto& node: docb.child("site_entries").children("entry"))
const char* idcs = node.child_value("id");
std::string id = new std::string(idcs, strlen(idcs));
if (!mapa.erase(id)) {
mapb[id] = node;
}
}
}
当我尝试编译它时,我似乎遇到了很多错误。
我得到的第一个是这个:
src/main.cpp:10:14: error: unknown type name 'string'; did you mean 'std::string'?
std::map<string, pugi::xml_node> mapa, mapb;
~~~~~^~~
据我了解,我已经正确指定了它。我应该按照它的要求更改它还是有其他问题?
最佳答案
您需要包含字符串库才能使用 std::string
.
因为你提到了很多错误,我怀疑你忘了包括<cstring>
为了使用 strlen()
.
#include <string>
#include <cstring>
关于c++ - 未知类型名称字符串 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29692326/