我偶然发现了一个有趣的问题。我已经设法将问题减少到以下代码:
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/