Cap*_*rsL 6 c++ winapi visual-studio-2010 boost-propertytree
好的,首先,我不是一个C++开发人员; 我已经设法把一些东西放在一起,它工作正常,但我确信通过专家的眼睛,它看起来像垃圾=)
所以我有一个免费软件应用程序,我使用Boost库中的Property Tree.我使用"使用多字节字符集"设置开发了整个应用程序(在VS2010中).我决定是时候通过并更新应用程序以支持Unicode,因为有些人有复杂的字符集,我想更好地支持.
我经历了一个繁琐的过程,即更改所有引用和调用以使用宽字符串,所有必要的转换.但是,我完全难以理解,我留下的唯一两个编译器错误.
它们都来自stream_translator.hpp(/ boost/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;
}
}
};
Run Code Online (Sandbox Code Playgroud)
第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
Run Code Online (Sandbox Code Playgroud)
..第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
Run Code Online (Sandbox Code Playgroud)
从我能够向后走,它来自stream_translator.hpp,最终从调用获取值[例如ptree.get("some.path","默认值在这里")]
我真的完全不知道如何解决这个问题,似乎无法在网上找到任何东西来帮助我理解究竟是什么问题.任何提示或信息将不胜感激.
编辑
所以我注释掉了与ptree相关的所有内容,直到它编译完成,然后开始重新添加它们.结果我可以调用.get,它是get_child,其中错误@ line 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
Run Code Online (Sandbox Code Playgroud)
猜测你遇到的问题是一样的...... Boost.PropertyTree的广泛字符版本支持unicode.
对于设置如下的Config.xml:
<?xml version="1.0"?>
<Zoo>
<Monkey>
<Food>Bananas</Food>
</Monkey>
</Zoo>
Run Code Online (Sandbox Code Playgroud)
使用与此类似的代码来解析它:
// 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");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4214 次 |
| 最近记录: |