【发布时间】:2014-04-10 09:38:32
【问题描述】:
我有一个类,我想以某种方式出现在日志中,所以我重载了它的 << 运算符:
class CWindowClassId
{
public:
// ...
friend std::wostream& operator<< (std::wostream& os, CWindowClassId const& classId);
}
在日志流中插入上面的类:
// ...
CWindowClassId classId(hWindow);
BOOST_LOG_TRIVIAL(debug) << "Window created, class = " << classId;
导致编译错误:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const Sandbox::CWindowClassId' (or there is no acceptable conversion) C:\local\boost_1_55_0\boost\log\utility\formatting_ostream.hpp 710
我知道错误在于,我为宽字符串重载了 <<。当我使用ostream 而不是wostream 时一切都很好,但我真的很想使用宽字符串版本。
我尝试为接收器设置区域设置:
shared_ptr<log::sinks::synchronous_sink<log::sinks::text_file_backend> > sink = log::add_file_log("log.txt");
sink->imbue(boost::locale::generator()("en_US.UTF-8"));
并且在任何与日志相关的包含之前定义BOOST_LOG_USE_WCHAR_T。
我可以做些什么来使用宽字符串<< 运算符进行日志记录?
我使用的是 Boost 1.55.0。
【问题讨论】:
-
缺乏对代码中所做工作的更完整视图,我建议您阅读参数相关查找
标签: c++ boost operator-overloading boost-log widestring