转换为 Unicode 时提升属性树问题
Boost property tree issue when converting to Unicode
好的,首先,我本质上不是C++开发人员;我已经设法将一些东西放在一起并且工作正常,但我敢肯定,通过专家的眼睛,它看起来像垃圾=(
所以我有一个我制作的免费软件应用程序,它使用来自 Boost 库的属性树。我使用"使用多字节字符集"设置开发了整个应用程序(在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;
}
}
};
第 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_0boostproperty_treestream_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_0boostproperty_treestream_translator.hpp 36 1
从我能够向后走过的内容来看,它来自 stream_translator.hpp 内部,最终开始于获取值的调用 [例如 ptree.get("some.path", "default value here"(]
我真的完全不知道如何解决这个问题,似乎无法在网上找到任何内容来帮助我了解问题到底是什么。 任何提示或信息将不胜感激。
编辑
所以我注释掉了与 ptree 相关的所有内容,直到它编译,然后开始重新添加它们。事实证明,我可以调用.get fine,这是弹出错误@行36的get_child(尚未完成其他项目,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
猜测你的问题和我遇到的一样......有宽字符版本的 Boost.PropertyTree 用于 unicode 支持。
对于配置.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");
}
}
- 在构造函数 c++ 中初始化属性时出现问题
- 我对 MyGraph 属性顶点名称和边权重有问题
- 在使用 std::sort() 和 lambda 函数按属性对 ADT 的向量进行排序时遇到问题
- 程序在没有输入的情况下退出,它有基本的,驱动的类属性初始化问题
- [[GNU :: pure]]功能属性和线程的优化问题
- 有关QT属性的问题
- 属性私有时遇到问题
- 更新对象的属性时遇到问题?
- 如何使用Qi :: Hold []解析器指令.(带有boost ::交换的属性类型的问题)
- 作用域问题:如何从类外查看(不访问也不修改!)私有属性
- Visual C++ 2013、TFS 和属性表的问题
- wx属性网格自定义滑块属性问题
- 将对象的属性传递到方法时出现作用域问题.(opencv相关)
- Boost.精神语法.属性和所有问题(_V)
- 灵气属性传播问题与单成员结构.
- 转换为 Unicode 时提升属性树问题
- 将get_value与 Boost 的属性树一起使用时遇到问题
- 问题:何时使用继承与设置属性
- 使用Google Protocol Buffer和Protobuf-C#将双重属性从C++转移到C#的问题
- CMFC "Delete"的网格属性问题