C++ 增强功能“;boost::property_tree::ini_parser::read_ini";引起;EXC“坏”访问(代码=EXC“I386”GPFLT)“;

C++ 增强功能“;boost::property_tree::ini_parser::read_ini";引起;EXC“坏”访问(代码=EXC“I386”GPFLT)“;,c++,boost,exc-bad-access,boost-propertytree,C++,Boost,Exc Bad Access,Boost Propertytree,我有这样一个简单的源代码,它在Windows 10下使用Visual Studio 2015正确构建和执行,但在OsX 10.11.3下使用Xcode 7.2.1抛出“EXC_BAD_ACCESS(code=EXC_I386_GPFLT)”: #include <boost/property_tree/ini_parser.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_t

我有这样一个简单的源代码,它在Windows 10下使用Visual Studio 2015正确构建和执行,但在OsX 10.11.3下使用Xcode 7.2.1抛出“EXC_BAD_ACCESS(code=EXC_I386_GPFLT)”:

#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{    
    if (argc != 3)
    {
        std::cerr << "Usage: program rootPath iniFileName" << std::endl ;
        return 1;
    }        

    string mainPath(argv[1]) ;
    string iniFileName(argv[2])  ;

    boost::property_tree::ptree pt;
    try
    {
        boost::property_tree::ini_parser::read_ini(mainPath + iniFileName, pt);
    }
    catch(const boost::property_tree::ptree_error &e)
    {
        cout << e.what() << endl;
    }

     return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main(int argc,char*argv[])
{    
如果(argc!=3)
{

std::cerr Boost代码看起来也不错;尝试将
std::locale()
作为第三个参数从代码中传递到
read\u ini
。可能有多个版本的标准库导致不兼容。“但是看起来属性树bug没有得到太多的关注”如果你不知道这是什么原因,那么把它称为Boost bug是没有帮助的。在OSX上ISTR区域设置实际上被破坏了。你也许可以找到一些关于这方面的信息online@CollinDauphinee:我已尝试添加std::locale(),但仍然执行错误访问,谢谢。如果执行
std::ifstream f,是否也会获得错误访问(mainPath+ini文件名);f.imbue(std::locale());
?@CollinDauphinee:不,这工作Boost代码看起来也不错;尝试从代码中将
std::locale()
作为第三个参数传递到
read_ini
。可能有多个版本的标准库导致不兼容。“但是看起来属性树bug并没有受到太多的关注”如果你不知道是什么原因,那么把它称为Boost bug也无济于事。在OSX上ISTR区域设置实际上被破坏了。你也许可以找到一些相关的东西online@CollinDauphinee:我已尝试添加std::locale()不过还是要谢谢你,谢谢。如果你使用
std::ifstream f(mainPath+ini文件名);f.imbue(std::locale());
,你的访问是否也不好?@CollinDauphinee:不,这样行
Thread 1Queue : com.apple.main-thread (serial) #0 0x00000001000a10c0 in std::1::basic_streambuf<char, std::1::char_traits<char> >::pubimbue(std::1::locale const&) [inlined] at /Applications/Xcode?.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/streambuf:227 #1 0x00000001000a10c0 in std::1::basic_ios<char, std::1::char_traits<char> >::imbue(std::1::locale const&) [inlined] at /Applications/Xcode?.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:717 #2 0x00000001000a100b in void boost::property_tree::ini_parser::read_ini<boost::property_tree::basic_ptree<std::__1::basic_string<char, std::__1::char_traits<char>, std::1::allocator<char> >, std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> >, std::1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::1::allocator<char> > > > >(std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> > const&, boost::property_tree::basic_ptree<std::__1::basic_string<char, std::__1::char_traits<char>, std::1::allocator<char> >, std::1::basic_string<char, std::1::char_traits<char>, std::1::allocator<char> >, std::1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::1::allocator<char> > > >&, std::1::locale const&) at /Users/andreagiovacchini/Documents/Sviluppo/boost_1_60_0/boost/property_tree/ini_parser.hpp:167 #3 0x0000000100124a36 in main at /Users/andreagiovacchini/Documents/Sviluppo/Test/Test/main.cpp:21 #4 0x00007fff857245ad in start () 
template<class Ptree>
    void read_ini(const std::string &filename, 
                  Ptree &pt,
                  const std::locale &loc = std::locale())
    {
        std::basic_ifstream<typename Ptree::key_type::value_type>
            stream(filename.c_str());
        if (!stream)
            BOOST_PROPERTY_TREE_THROW(ini_parser_error(
                "cannot open file", filename, 0));
        stream.imbue(loc);
        try {
            read_ini(stream, pt);
        }
        catch (ini_parser_error &e) {
            BOOST_PROPERTY_TREE_THROW(ini_parser_error(
                e.message(), filename, e.line()));
        }
    }