-->

转换为Unicode时提升属性树问题(Boost property tree issue when

2019-06-24 09:04发布

好吧,首先我不是一个天生的C ++开发者; 我已经成功地把一些东西一起工作得很好,但我敢肯定,通过它看起来像垃圾的专家眼中=)

所以我有一个使用属性树从Boost库一个免费的应用程序,我所做的。 我公司开发的整个应用程序(在VS2010)与使用多字节字符集设置。 我决定是时间去和有一些乡亲,我想更好地支持复杂的字符集的更新应用,以支持Unicode。

我通过改变所有引用的繁琐过程去,并呼吁使用宽字符串,所有必要的转换。 不过,我完全在一个点难住了,只有两个编译器错误,我已经离开。

它们都来自stream_translator.hpp(/升压/ property_tree /),线33和36(如下所述):

template <typename Ch, typename Traits, typename E, typename Enabler = void>
struct customize_stream
{
    static void insert(std::basic_ostream<Ch, Traits>& s, const E& e) {
        s << e; //line 33
    }
    static void extract(std::basic_istream<Ch, Traits>& s, E& e) {
        s >> e; //line 36
        if(!s.eof()) {
            s >> std::ws;
        }
    }
};

在线路33上的误差为:

Error   347 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::wstring' (or there is no acceptable conversion)   {...}\boost_1_49_0\boost\property_tree\stream_translator.hpp    33  1   

在..和线36的错误是:

Error   233 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion) {...}\boost_1_49_0\boost\property_tree\stream_translator.hpp    36  1

从我已经能够通过倒退行走,它是从[(“在这里默认值”“some.path”,)如ptree.get]未来stream_translator.hpp内最终开始为呼叫得到一个值

我真的完全不知道如何解决这个问题,似乎无法找到任何在网上帮我了解到底是什么问题。 任何提示或信息,将不胜感激。

编辑

所以我注释掉与ptree中,直到它会编译一切,然后开始将它们添加回。事实证明,我可以打电话。获得精细,它的get_child在错误@线36个弹起(没有做其他的项目还没有,其中wstring的问题)。

为简单起见,这里是电话,这是罚款,直至get_child被称为有效序列:

boost::property_tree::ptree pt; 
boost::property_tree::read_xml("Config.xml", pt);
int iAppSetting = pt.get("config.settings.AppSetting",1); //<- works fine
ptree ptt;
ptt = pt.get_child("config.Applications"); //<- adding this line causes the line 36 error

Answer 1:

猜测你的问题是我遇到同样的......有支持Unicode Boost.PropertyTree的宽字符版本。

对于Config.xml中就是这样的设置:

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

使用类似的代码这对它进行解析:

// 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");
    }
}


文章来源: Boost property tree issue when converting to Unicode