• 【原】error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'


    今天遇到一个非常难以排查的BUG,谷歌度娘都问过了依旧无解,最后自己重新尝试之后找到解决方案:

    先看一下报错信息:

    1>.lenz.cpp(2197)  error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
    1>        D:Program FilesVCincludeostream(650): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<wchar_t,std::char_traits<wchar_t>>(std::basic_ostream<_Elem,_Traits> &,const char *)'
    1>        with
    1>        [
    1>            _Elem=wchar_t,
    1>            _Traits=std::char_traits<wchar_t>
    1>        ]
    1>        D:Program FilesVCincludeostream(697): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<wchar_t,std::char_traits<wchar_t>>(std::basic_ostream<_Elem,_Traits> &,char)'
    1>        with
    1>        [
    1>            _Elem=wchar_t,
    1>            _Traits=std::char_traits<wchar_t>
    1>        ]
    ......//一行出错后就会有一堆这样的With[]....出现,非常烦

    网上搜了一下,很多人说是因为没有#include <string>的缘故,但是反复确认后发现我有做到。百思不得其解,还一度以为是不同文件的头文件重复引用导致<string>失效,但是这条说不通!后面冷静了之后,双击错误信息查看源码,发现基本上这些错误含有两个特征:

    1.都是LOG4CPLUS_DEBUG等调试函数

    2.参数都有string类型

    然后我单独写了一小段程序验证了一下,好家伙,真是这样子。原来,LOG4CPLUS_DEBUG函数不能直接打印string对象,只支持其转换形式.c_str()。

    解决方法:把所有的LOG4CPLUS_DEBUG函数中的string加个c_str()

  • 相关阅读:
    Mac连接远程Linux管理文件(samba)
    centos6 防火墙iptables操作整理
    安装postgresql
    linux CentOS6.5 yum安装mysql 5.6
    centos--git搭建之Gogs安装
    查看mysql 默认端口号和修改端口号
    centos之mysql安装配置使用
    流媒体服务器SRS部署
    redis配置文件参数说明
    redis 安装
  • 原文地址:https://www.cnblogs.com/wengzilin/p/3745738.html
Copyright © 2020-2023  润新知