C++ 프로그램에서 RapidXml을 사용하고 있습니다. 잘 됐어. 괜찮아. 문제 없어.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 위키 페이지를 살펴 경우 내가 ... 변수 값 대신 를 포인터를 사용해야하는 이유 난 그냥 이해가 안 돼요, 제공되는 몇 가지 예는,이 RapidXml 개발자가 제공하는 하나입니다 왜 xml_node에 대한 포인터를 사용합니까? 나는 xml_node을 반환하는 함수에 필요하기 때문에
나는이 할 그렇다면 ...
을이 질문 = ... 반환 *의 MYNODE
xml_node에게 <> * MYNODE을;
괜찮습니까 ?? 왜냐하면 나중에 반환 된 노드와 모든 자식을 나중에 사용하려고하기 때문입니다. 이렇게하면 좋습니까? 그렇지 않으면 어떻게해야합니까?
-1 다른 두 사람이 이미 답변 한 후에도 자신의 질문에 대한 답변을 얻으려면 기본적으로 매우 오랫동안 말했듯이 일관성이없는 것으로 반복합니다. 또한 "도서관을 살펴보십시오"라고 말합니다. 다른 사람에게 도움을 요청한 다음 자신의 대답을 훔쳐 다른 사람에게 스스로 알아 내려고합니다. 쿨하지 않아. –