c++ - 尝试使用 boost 读取 xml 时出现空指针

标签 c++ xml boost

我偶然发现了一个有趣的问题。我已经设法将问题减少到以下代码:

boost::property_tree::ptree properties;
boost::property_tree::read_xml("Additional Dependencies\\properties.xml", properties);

xml:

<Properties>

  <PictureGenerator>
    <miniatureHeight>4</miniatureHeight>
    <miniatureWidth>4</miniatureWidth>

    <imageHeight>8</imageHeight>
    <imageWidth>8</imageWidth>

    <ImagePath>Additional Dependencies\</ImagePath>
    <Miniatures>
      <Image>0.bmp</Image>
      <Image>1.bmp</Image>
      <!--<Image>2.bmp</Image>
      <Image>3.bmp</Image>
      <Image>4.bmp</Image>-->
    </Miniatures>

  </PictureGenerator>
</Properties>

当我在 Release模式下构建项目时,一切都运行完美。 在 Debug模式下,出现以下错误:

Unhandled exception at 0x779e8e19 in my_project.exe: 0xC0000005: Access violation writing location 0x00000014.

我正在使用 VS2010。 经过进一步检查,在尝试从 basic_istream 创建 vector 时,read_xml_internal 函数中抛出错误。 起初我以为我给了错误的路径,但我在 Release 模式下工作得很好。

最佳答案

我找到了问题的根源。 我用 istream 重现了同样的错误,事实证明我为 Debug 设置了错误的属性页。

问题是属性:

C/C++ -> Code Generation -> Runtime Libary as Multi-threaded

我已将其更改为 Multi-threaded Debug Dll 并且它运行良好。

关于c++ - 尝试使用 boost 读取 xml 时出现空指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19209872/

相关文章:

php - DOMNode 到 PHP 中的 DOMElement

android 更改 TextView (这段代码可以吗?)

c++ - boost::asio::deadline_timer 线程安全吗?

multithreading - Boost:可能从任何线程解锁互斥锁吗?

java - Network Mapper软件的最佳平台和编程语言

c++ - MSVS C++ 2012 : how to disable compiling-while-editting

c++ - 错误 : invalid argument '-std=gnu99' not allowed with 'C++/ObjC++'

C++ amp 原子

java - 如何在通过 SAX Xerces 解析 XML 文档时引用 XSD 架构位置?

c++ - 使用已删除的函数 CONSTRUCTOR,没有匹配的调用函数