Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/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
C++ rapidXML解析错误行为_C++_Rapidxml - Fatal编程技术网

C++ rapidXML解析错误行为

C++ rapidXML解析错误行为,c++,rapidxml,C++,Rapidxml,我正在尝试解析xml文件: <?xml version="1.0"?> <settings> <output>test.dat</output> <width>5</width> <depth>4</depth> <height>10</height> </settings> 当我尝试访问任何节点时,这会导致异常。我想我遗漏了一些明

我正在尝试解析xml文件:

<?xml version="1.0"?>
<settings>
    <output>test.dat</output>
    <width>5</width>
    <depth>4</depth>
    <height>10</height>
</settings>
当我尝试访问任何节点时,这会导致异常。我想我遗漏了一些明显的东西,但到目前为止我还不明白

如果我尝试以下方法:

std::cout << doc.first_node("output")->value();
std::cout value();

我在读取位置0x00000004时收到一条消息,表示存在访问冲突。

文档没有名为“output”的节点。文档有一个名为“settings”的节点,该节点又有一个名为“output”的节点。下面的代码

  std::ifstream file("settings.xml");
  std::vector<char> content = std::vector<char>(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
  content.push_back('\0');

  rapidxml::xml_document<> doc;
  doc.parse<0 | rapidxml::parse_no_data_nodes>(&content[0]);

  rapidxml::xml_node<> * root = doc.first_node();
  for (rapidxml::xml_node<> * node = root->first_node(); node; node = node->next_sibling())
  {
    std::cout << "value of <" << node->name() << "> is " << node->value() << std::endl;
  }
std::ifstream文件(“settings.xml”);
std::vector content=std::vector(std::istreambuf_迭代器(文件),std::istreambuf_迭代器());
content.push_back('\0');
rapidxml::xml_文档文档;
文档解析(&content[0]);
rapidxml::xml_node*root=doc.first_node();
对于(rapidxml::xml_node*node=root->first_node();node;node=node->next_sibling())
{

std::cout您的问题到底是什么?IIRC,rapidxml解析对传递的字符*进行“破坏性”读取,因此它可以很好地在内部某处插入“\0”(我猜是在“test.dat”中的“t”之后、“5”之后、“4”和“10”中的“0”之后)你能展示你用来访问节点的代码吗?你得到了什么异常?rapidxml::parse_错误异常?
std::cout << doc.first_node("output")->value();
  std::ifstream file("settings.xml");
  std::vector<char> content = std::vector<char>(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
  content.push_back('\0');

  rapidxml::xml_document<> doc;
  doc.parse<0 | rapidxml::parse_no_data_nodes>(&content[0]);

  rapidxml::xml_node<> * root = doc.first_node();
  for (rapidxml::xml_node<> * node = root->first_node(); node; node = node->next_sibling())
  {
    std::cout << "value of <" << node->name() << "> is " << node->value() << std::endl;
  }
value of <output> is test.dat
value of <width> is 5
value of <depth> is 4
value of <height> is 10