Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ RapidXML:无法打印-编译时错误_C++_Xml_Printf_Cout_Rapidxml - Fatal编程技术网

C++ RapidXML:无法打印-编译时错误

C++ RapidXML:无法打印-编译时错误,c++,xml,printf,cout,rapidxml,C++,Xml,Printf,Cout,Rapidxml,我尝试在我的C++应用程序中使用RAPIDXML库打印控制台中的XML文档数据。 我正在遵循RapidXML手册,但是我遇到了一个编译时错误 < >强>这里是我的C++代码:< /强> #include <iostream> #include "rapidxml.hpp" #include "rapidxml_utils.hpp" #include "rapidxml_print.hpp" int main() { rapidxml::file<> xmlFi

我尝试在我的C++应用程序中使用RAPIDXML库打印控制台中的XML文档数据。 我正在遵循RapidXML手册,但是我遇到了一个编译时错误

< >强>这里是我的C++代码:< /强>

#include <iostream>
#include "rapidxml.hpp"
#include "rapidxml_utils.hpp"
#include "rapidxml_print.hpp"

int main() {
    rapidxml::file<> xmlFile("beerJournal.xml");
    rapidxml::xml_document<> doc;
    doc.parse<0>(xmlFile.data());

    std::cout << doc;

    return 0;
}
rapidxml_print.hpp:115: error: ‘print_children’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
                 out = print_children(out, node, flags, indent);
                       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

rapidxml_print.hpp:169: ‘template<class OutIt, class Ch> OutIt rapidxml::internal::print_children(OutIt, const rapidxml::xml_node<Ch>*, int, int)’ declared here, later in the translation unit
         inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
                      ^~~~~~~~~~~~~~
#包括
#包括“rapidxml.hpp”
#包括“rapidxml_utils.hpp”
#包括“rapidxml_print.hpp”
int main(){
rapidxml::文件xmlFile(“beerJournal.xml”);
rapidxml::xml_文档文档;
parse(xmlFile.data());

std::cout我在过去也遇到过同样的问题。中介绍的解决方法在我的所有GCC构建中都非常有效

总结另一个答案的信息:它归结为GCC 4.7中的名称查找更改。解决方法包括创建一个名为
rapidxml_ext.hpp
的文件,其中包含以下内容。然后将
rapidxml_ext.hpp
包含在客户端应用程序/库中

rapidxml\u ext.hpp

#pragma once

#include "rapidxml.hpp"

// Adding declarations to make it compatible with gcc 4.7 and greater
// See https://stackoverflow.com/a/55408678
namespace rapidxml {
    namespace internal {
        template <class OutIt, class Ch>
        inline OutIt print_children(OutIt out, const xml_node<Ch>* node, int flags, int indent);

        template <class OutIt, class Ch>
        inline OutIt print_attributes(OutIt out, const xml_node<Ch>* node, int flags);

        template <class OutIt, class Ch>
        inline OutIt print_data_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);

        template <class OutIt, class Ch>
        inline OutIt print_cdata_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);

        template <class OutIt, class Ch>
        inline OutIt print_element_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);

        template <class OutIt, class Ch>
        inline OutIt print_declaration_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);

        template <class OutIt, class Ch>
        inline OutIt print_comment_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);

        template <class OutIt, class Ch>
        inline OutIt print_doctype_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);

        template <class OutIt, class Ch>
        inline OutIt print_pi_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
    }
}

#include "rapidxml_print.hpp"
#pragma一次
#包括“rapidxml.hpp”
//添加声明以使其与gcc 4.7及更高版本兼容
//看https://stackoverflow.com/a/55408678
命名空间rapidxml{
命名空间内部{
模板
内联OutIt print_子项(OutIt out、常量xml_node*node、int标志、int缩进);
模板
内联输出打印_属性(输出、常量xml_节点*节点、int标志);
模板
内联输出打印数据节点(输出、常量xml节点*节点、整型标志、整型缩进);
模板
内联输出打印\u cdata\u节点(输出、常量xml\u节点*节点、整型标志、整型缩进);
模板
内联输出打印元素节点(输出、常量xml节点*节点、整型标志、整型缩进);
模板
内联输出输出输出声明节点(输出输出、常量xml输出节点*节点、整型标志、整型缩进);
模板
内联输出打印注释节点(输出、常量xml节点*节点、整型标志、整型缩进);
模板
内联输出打印\u doctype\u节点(输出、常量xml\u节点*节点、int标志、int缩进);
模板
内联输出打印节点(输出、常量xml节点*节点、整型标志、整型缩进);
}
}
#包括“rapidxml_print.hpp”