我是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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我似乎遇到了很多错误.
我得到的第一个是:
src/main.cpp:10:14: error: unknown type name 'string'; did you mean 'std::string'?
std::map<string, pugi::xml_node> mapa, mapb;
~~~~~^~~
Run Code Online (Sandbox Code Playgroud)
据我所知,我已正确指定.我应该按照要求改变它还是别的什么?
您需要包含字符串库才能使用std::string.
由于您提到了很多错误,我怀疑您忘记包含<cstring>以便使用strlen().
#include <string>
#include <cstring>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17868 次 |
| 最近记录: |