Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.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

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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
试图理解RapidXml内存分配 我在一个C++程序中使用了RAPIDXML。好的,没问题,它能用。我只是不明白为什么我必须使用指针而不是变量值。。。 如果查看RapidXml wiki页面,将提供一些示例,这是RapidXml开发人员提供的示例: #include <iostream> #include <string> #include "rapidxml-1.13/rapidxml.hpp" #include "rapidxml-1.13/rapidxml_print.hpp" int main(int argc, char** argv); int main(int argc, char** argv) { using namespace rapidxml; xml_document<> doc; // xml declaration xml_node<>* decl = doc.allocate_node(node_declaration); decl->append_attribute(doc.allocate_attribute("version", "1.0")); decl->append_attribute(doc.allocate_attribute("encoding", "utf-8")); doc.append_node(decl); // root node xml_node<>* root = doc.allocate_node(node_element, "rootnode"); root->append_attribute(doc.allocate_attribute("version", "1.0")); root->append_attribute(doc.allocate_attribute("type", "example")); doc.append_node(root); // child node xml_node<>* child = doc.allocate_node(node_element, "childnode"); root->append_node(child); xml_node<>* child2 = doc.allocate_node(node_element, "childnode"); root->append_node(child2); std::string xml_as_string; // watch for name collisions here, print() is a very common function name! print(std::back_inserter(xml_as_string), doc); std::cout << xml_as_string << std::endl; // xml_as_string now contains the XML in string form, indented // (in all its angle bracket glory) std::string xml_no_indent; // print_no_indenting is the only flag that print() knows about print(std::back_inserter(xml_no_indent), doc, print_no_indenting); // xml_no_indent now contains non-indented XML std::cout << xml_no_indent << std::endl; } #包括 #包括 #包括“rapidxml-1.13/rapidxml.hpp” #包括“rapidxml-1.13/rapidxml_print.hpp” int main(int argc,字符**argv); int main(int argc,字符**argv){ 使用名称空间rapidxml; xml_文档文档; //xml声明 xml\u node*decl=doc.allocate\u node(node\u声明); decl->append_属性(文档分配_属性(“版本”、“1.0”); decl->append_属性(文档分配_属性(“编码”、“utf-8”); 单据追加节点(decl); //根节点 xml_node*root=doc.allocate_node(node_元素,“rootnode”); root->append_属性(文档分配_属性(“版本”、“1.0”); 根->附加属性(单据分配属性(“类型”、“示例”); 单据追加节点(根节点); //子节点 xml_node*child=doc.allocate_node(node_元素,“childnode”); 根->附加节点(子节点); xml_node*child2=doc.allocate_节点(node_元素,“childnode”); 根->附加节点(child2); std::string xml_作为_字符串; //注意这里的名称冲突,print()是一个非常常见的函数名! 打印(std::back\u插入器(xml\u as\u字符串),doc); 标准::cout_C++_Xml_Pointers_Return Value_Rapidxml - Fatal编程技术网 append_属性(文档分配_属性(“版本”、“1.0”); decl->append_属性(文档分配_属性(“编码”、“utf-8”); 单据追加节点(decl); //根节点 xml_node*root=doc.allocate_node(node_元素,“rootnode”); root->append_属性(文档分配_属性(“版本”、“1.0”); 根->附加属性(单据分配属性(“类型”、“示例”); 单据追加节点(根节点); //子节点 xml_node*child=doc.allocate_node(node_元素,“childnode”); 根->附加节点(子节点); xml_node*child2=doc.allocate_节点(node_元素,“childnode”); 根->附加节点(child2); std::string xml_作为_字符串; //注意这里的名称冲突,print()是一个非常常见的函数名! 打印(std::back\u插入器(xml\u as\u字符串),doc); 标准::cout,c++,xml,pointers,return-value,rapidxml,C++,Xml,Pointers,Return Value,Rapidxml" /> append_属性(文档分配_属性(“版本”、“1.0”); decl->append_属性(文档分配_属性(“编码”、“utf-8”); 单据追加节点(decl); //根节点 xml_node*root=doc.allocate_node(node_元素,“rootnode”); root->append_属性(文档分配_属性(“版本”、“1.0”); 根->附加属性(单据分配属性(“类型”、“示例”); 单据追加节点(根节点); //子节点 xml_node*child=doc.allocate_node(node_元素,“childnode”); 根->附加节点(子节点); xml_node*child2=doc.allocate_节点(node_元素,“childnode”); 根->附加节点(child2); std::string xml_作为_字符串; //注意这里的名称冲突,print()是一个非常常见的函数名! 打印(std::back\u插入器(xml\u as\u字符串),doc); 标准::cout,c++,xml,pointers,return-value,rapidxml,C++,Xml,Pointers,Return Value,Rapidxml" />

试图理解RapidXml内存分配 我在一个C++程序中使用了RAPIDXML。好的,没问题,它能用。我只是不明白为什么我必须使用指针而不是变量值。。。 如果查看RapidXml wiki页面,将提供一些示例,这是RapidXml开发人员提供的示例: #include <iostream> #include <string> #include "rapidxml-1.13/rapidxml.hpp" #include "rapidxml-1.13/rapidxml_print.hpp" int main(int argc, char** argv); int main(int argc, char** argv) { using namespace rapidxml; xml_document<> doc; // xml declaration xml_node<>* decl = doc.allocate_node(node_declaration); decl->append_attribute(doc.allocate_attribute("version", "1.0")); decl->append_attribute(doc.allocate_attribute("encoding", "utf-8")); doc.append_node(decl); // root node xml_node<>* root = doc.allocate_node(node_element, "rootnode"); root->append_attribute(doc.allocate_attribute("version", "1.0")); root->append_attribute(doc.allocate_attribute("type", "example")); doc.append_node(root); // child node xml_node<>* child = doc.allocate_node(node_element, "childnode"); root->append_node(child); xml_node<>* child2 = doc.allocate_node(node_element, "childnode"); root->append_node(child2); std::string xml_as_string; // watch for name collisions here, print() is a very common function name! print(std::back_inserter(xml_as_string), doc); std::cout << xml_as_string << std::endl; // xml_as_string now contains the XML in string form, indented // (in all its angle bracket glory) std::string xml_no_indent; // print_no_indenting is the only flag that print() knows about print(std::back_inserter(xml_no_indent), doc, print_no_indenting); // xml_no_indent now contains non-indented XML std::cout << xml_no_indent << std::endl; } #包括 #包括 #包括“rapidxml-1.13/rapidxml.hpp” #包括“rapidxml-1.13/rapidxml_print.hpp” int main(int argc,字符**argv); int main(int argc,字符**argv){ 使用名称空间rapidxml; xml_文档文档; //xml声明 xml\u node*decl=doc.allocate\u node(node\u声明); decl->append_属性(文档分配_属性(“版本”、“1.0”); decl->append_属性(文档分配_属性(“编码”、“utf-8”); 单据追加节点(decl); //根节点 xml_node*root=doc.allocate_node(node_元素,“rootnode”); root->append_属性(文档分配_属性(“版本”、“1.0”); 根->附加属性(单据分配属性(“类型”、“示例”); 单据追加节点(根节点); //子节点 xml_node*child=doc.allocate_node(node_元素,“childnode”); 根->附加节点(子节点); xml_node*child2=doc.allocate_节点(node_元素,“childnode”); 根->附加节点(child2); std::string xml_作为_字符串; //注意这里的名称冲突,print()是一个非常常见的函数名! 打印(std::back\u插入器(xml\u as\u字符串),doc); 标准::cout

试图理解RapidXml内存分配 我在一个C++程序中使用了RAPIDXML。好的,没问题,它能用。我只是不明白为什么我必须使用指针而不是变量值。。。 如果查看RapidXml wiki页面,将提供一些示例,这是RapidXml开发人员提供的示例: #include <iostream> #include <string> #include "rapidxml-1.13/rapidxml.hpp" #include "rapidxml-1.13/rapidxml_print.hpp" int main(int argc, char** argv); int main(int argc, char** argv) { using namespace rapidxml; xml_document<> doc; // xml declaration xml_node<>* decl = doc.allocate_node(node_declaration); decl->append_attribute(doc.allocate_attribute("version", "1.0")); decl->append_attribute(doc.allocate_attribute("encoding", "utf-8")); doc.append_node(decl); // root node xml_node<>* root = doc.allocate_node(node_element, "rootnode"); root->append_attribute(doc.allocate_attribute("version", "1.0")); root->append_attribute(doc.allocate_attribute("type", "example")); doc.append_node(root); // child node xml_node<>* child = doc.allocate_node(node_element, "childnode"); root->append_node(child); xml_node<>* child2 = doc.allocate_node(node_element, "childnode"); root->append_node(child2); std::string xml_as_string; // watch for name collisions here, print() is a very common function name! print(std::back_inserter(xml_as_string), doc); std::cout << xml_as_string << std::endl; // xml_as_string now contains the XML in string form, indented // (in all its angle bracket glory) std::string xml_no_indent; // print_no_indenting is the only flag that print() knows about print(std::back_inserter(xml_no_indent), doc, print_no_indenting); // xml_no_indent now contains non-indented XML std::cout << xml_no_indent << std::endl; } #包括 #包括 #包括“rapidxml-1.13/rapidxml.hpp” #包括“rapidxml-1.13/rapidxml_print.hpp” int main(int argc,字符**argv); int main(int argc,字符**argv){ 使用名称空间rapidxml; xml_文档文档; //xml声明 xml\u node*decl=doc.allocate\u node(node\u声明); decl->append_属性(文档分配_属性(“版本”、“1.0”); decl->append_属性(文档分配_属性(“编码”、“utf-8”); 单据追加节点(decl); //根节点 xml_node*root=doc.allocate_node(node_元素,“rootnode”); root->append_属性(文档分配_属性(“版本”、“1.0”); 根->附加属性(单据分配属性(“类型”、“示例”); 单据追加节点(根节点); //子节点 xml_node*child=doc.allocate_node(node_元素,“childnode”); 根->附加节点(子节点); xml_node*child2=doc.allocate_节点(node_元素,“childnode”); 根->附加节点(child2); std::string xml_作为_字符串; //注意这里的名称冲突,print()是一个非常常见的函数名! 打印(std::back\u插入器(xml\u as\u字符串),doc); 标准::cout,c++,xml,pointers,return-value,rapidxml,C++,Xml,Pointers,Return Value,Rapidxml,那么,为什么它使用指向xml_节点的指针呢 可能是因为返回指向节点的指针比在返回时复制要快 那么,为什么它使用指向xml_节点的指针呢 可能是因为返回指向节点的指针比在返回时复制要快。返回指针可能是为了避免调用节点的复制构造函数。只返回指针更快,特别是考虑到节点可能已经在内部分配了某个位置 他们还可以返回一个引用,但他们可能希望保留在无效调用时返回NULL的功能 如果您需要一个xml_节点,您可以随时取消对指针的引用(首先检查NULL)。但是,如果您确实希望稍后使用返回的节点及其子节点,则最好只

那么,为什么它使用指向xml_节点的指针呢

可能是因为返回指向节点的指针比在返回时复制要快

那么,为什么它使用指向xml_节点的指针呢


可能是因为返回指向节点的指针比在返回时复制要快。

返回指针可能是为了避免调用节点的复制构造函数。只返回指针更快,特别是考虑到节点可能已经在内部分配了某个位置

他们还可以返回一个引用,但他们可能希望保留在无效调用时返回NULL的功能


如果您需要一个xml_节点,您可以随时取消对指针的引用(首先检查NULL)。但是,如果您确实希望稍后使用返回的节点及其子节点,则最好只使用->返回的指针,并按值传递指针。

返回指针可能是为了避免调用节点的复制构造函数。只返回指针更快,尤其是考虑到该节点是专业的bably已经在内部分配了位置

他们还可以返回一个引用,但他们可能希望保留在无效调用时返回NULL的功能


如果您需要一个xml_节点,您可以随时取消对指针的引用(首先检查NULL)。但是,如果您以后真的想使用返回的节点及其子节点,可能最好只使用返回的指针和->并通过值传递指针。

好吧……RapidXML和许多其他类似Xerces的工具都不返回值,而是返回指针,这样程序员就不能一直使用值并进行复制了……t他这样做是为了保存记忆

特别是在谈到DOM时,但对于SAX来说几乎是一样的,这些解析器需要在运行程序的计算机RAM中创建一个非常复杂的内存分配结构。 为了提供性能等,所有构造函数和复制构造函数都是私有的

看看图书馆……你会发现这个好把戏啊哈

嗯,原因是我报告的,每个人都建议我


我想,在使用C、C++和低级语言时,程序不是直接的…程序员不能很好地取一个节点并通过它或返回函数和类。

< P> ok……RapidXML和许多像XeRCE这样的人不返回值,而是指针,这样程序员就无法把值取下来并做成Co。一直都是馅饼…这是为了保存记忆

特别是在谈到DOM时,但对于SAX来说几乎是一样的,这些解析器需要在运行程序的计算机RAM中创建一个非常复杂的内存分配结构。 为了提供性能等,所有构造函数和复制构造函数都是私有的

看看图书馆……你会发现这个好把戏啊哈

嗯,原因是我报告的,每个人都建议我


我想,当使用C、C++和低级语言时,程序不是直接的程序…程序员不能很好地取一个节点并传递它或返回函数和类。在两个其他人已经回答了问题之后,你回答了你自己的问题,你基本上重复了他们刚才说的冗长的话。不太连贯。你还说“看看图书馆”.在请别人帮助你之后,告诉别人自己去想办法,然后窃取他们的答案。这不酷。-1在其他两个人已经回答了你自己的问题之后,你很好地回答了你自己的问题,你基本上重复了他们说的话,只是很冗长,不太连贯。你还说“看看图书馆”.告诉别人在请求别人帮助后自己去想办法,然后窃取他们的答案。这不酷。