rapidxml介绍:略
也许你下载了rapidxml以后,想在UNICODE模式下使用,但编译时会失败并提示错误,该错误提示如下:
error C2440: '<function-style-cast>' : cannot convert from 'std::basic_ostream<_Elem,_Traits>' to 'std::ostream_iterator<_Ty>'
既然给了提示,意思是说:给定的参数类型与函数所需类型不正确,那么我们就解决之。
以下代码均在rapidxml_print.hpp文件中400行位置:
首先我们看一看print参数模板:
template<class _Ty, class _Elem = char, class _Traits = char_traits<_Elem> >
class ostream_iterator
然后再看一看print函数模板:
template<class Ch>
inline std::basic_ostream<Ch> &print(std::basic_ostream<Ch> &out, const xml_node<Ch> &node, int flags = 0)
对于Ch类型来说,就是为了指定函数的能解析的字符集,那么我们这里可以是chat,wchar_t,当然自动化的TCHAR也行。
然而我们再看一看函数在转换参数模板的地方:
print(std::ostream_iterator<Ch>(out), node, flags);
这里在转换迭代器的时候,虽然把字符集给指定了,但没有指定函数转换集,因为我们需要改为:
print(std::ostream_iterator<Ch,Ch>(out), node, flags);
因为ostream_iterator的第二个模板参数默认是char,当我们需要用wchar_t解析的时候,这里参数类型肯定不对。
不知道这个BUG是作者的笔误还是怎么的,我们不用管,到此,在UNICODE模式下用rapidxml写xml文件即可成功。
写文件的方法,看代码:
!!!请注意!!!:
上面代码如果在UNICODE下编译通过,请先按如下修改:
rapidxml_print.hpp文件中403行:
print(std::ostream_iterator<Ch>(out), node, flags);
修改为:
print(std::ostream_iterator<Ch,Ch>(out), node, flags);
1693

被折叠的 条评论
为什么被折叠?



