过载运算符 << 提升日志
overload operator << Boost Log
inline std::ostream& operator<<(std::ostream& p, const std::vector<unsigned int>& vector){
p << "[ ";
for(auto i:vector){
p << " "<< i << " ,";
}
p<< "]";
return p;
}
#define LOG_DEBUG_MESSAGE BOOST_LOG_SEV(my_logger::get(), debug)
std::vector<unsigned int> test {1, 2, 3};
LOG_DEBUG_MESSAGE << "test "<< test;
std::cout << test << std::endl;
你好
我重载了我的运算符<<以获得 std::vector。当我使用 std::cout 时,它运行良好,但使用提升日志时,我收到以下错误:
提升/日志/实用程序/formatting_ostream.hpp:710:19:错误:无法绑定 'boost::log::v2_mt_posix::basic_formatting_ostream::ostream_type {aka std::basic_ostream}' lvalue to 'std::basic_ostream&&' strm.stream(( <<值;
/opt/gcc.4.9.1/include/c++/4.9.1/ostream:602:5:注意:正在初始化 'std::basic_ostream<_CharT, _Traits>& 的参数 1 std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&( [_CharT = 字符;_Traits = std::char_traits; _Tp = std::vector]' operator<<(basic_ostream<_CharT, _Traits>&__os, const _Tp& __x(
我不知道为什么提升日志不起作用。它使用相同的<<运算符或?在其他具有自己的类的示例中,它适用于重载。我不知道我错过了什么。有人知道我如何解决此错误吗?
'boost::log::basic_formatting_ostream 不是从 std::ostream 派生的。
你应该重载 std::vector 的运算符<<,重载运算符应该将 boost::log::formatting_ostream& 作为它的第一个参数。
检查下面修改后的代码示例:
inline boost::log::formatting_ostream& operator<<(boost::log::formatting_ostream& p, std::vector<int>& vector)
{
p << "[ ";
for(auto i:vector){
p << " "<< i << " ,";
}
p<< "]";
return p;
}
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 是否可以配置提升日志刷新?
- 跟踪日志中的T.11803()是什么意思?
- 加快在C++中读取/处理日志文件的速度
- 如何将消息时间戳写入日志文件?
- 分析包含 NMEA 句子的日志文件C++
- 如何修复输出日志中的"EnableInput can only be specified on a Pawn for its Controller"错误
- 如何实现具有多个平台__FILE__和__LINE__信息的 C/C++ 可变参数日志记录宏?
- Log4net,将日志消息从 c++ dll 发送到 c# 应用程序?
- 返回ERROR_INVALID_PARAMETER的事件日志函数
- 为什么系统日志有两个不同的函数声明?
- 从更改日志获取最新的 USN 数据
- 如何从日志文件中抓取状态代码?(在 C++ 中)
- 未创建日志文件
- C++ 中混合二进制/文本日志记录的最佳做法
- 将日志宏转换为目标 C 字符串