Boost property tree issue when converting to Unicode

前端 未结 1 406
不思量自难忘°
不思量自难忘° 2021-01-12 17:56

Ok, first off I\'m not a C++ developer by nature; I\'ve managed to put some stuff together and it works fine, but I\'m sure through the eyes of an expert it looks like garba

相关标签:
1条回答
  • 2021-01-12 18:50

    Guessing that your problem was the same I ran into... There are wide character versions of Boost.PropertyTree for unicode support.

    For Config.xml that is setup like this:

    <?xml version="1.0"?>
    <Zoo>
        <Monkey>
            <Food>Bananas</Food>
        </Monkey>
    </Zoo>
    

    Use code similar to this to parse it:

    // Load up the property tree for wide characters
    boost::property_tree::wptree pt;
    boost::property_tree::read_xml("Config.xml", pt);
    
    // Iterate
    BOOST_FOREACH(wptree::value_type const& v, pt.get_child(L"Zoo"))
    {
        if( v.first == L"Monkey" )
        {
            wstring foodType = v.second.get<wstring>(L"Food");
        }
    }
    
    0 讨论(0)
提交回复
热议问题