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

简介:

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

先看一下报错信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
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 Files\VC\include\ostream(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 Files\VC\include\ostream(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>        ]<br>...... //一行出错后就会有一堆这样的With[]....出现,非常烦

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

1.都是LOG4CPLUS_DEBUG等调试函数

2.参数都有string类型

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

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


本文转自编程小翁博客园博客,原文链接:http://www.cnblogs.com/wengzilin/p/3745738.html,如需转载请自行联系原作者

相关文章
|
4月前
|
前端开发 Java 数据库连接
Spring Boot 升级 3.2 报错 Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String
Spring Boot 升级 3.2 报错 Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String
|
1月前
|
C++
C++ std::string类的使用
C++ std::string类的使用
21 0
|
6月前
解决Missing cookie ‘JssionId‘ for method parameter of type String问题
解决Missing cookie ‘JssionId‘ for method parameter of type String问题
|
4月前
Excel上传出错:TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string or an instan
Excel上传出错:TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string or an instan
|
5月前
|
编译器
error TS2322 Type ‘string null‘ is not assignable to type ‘string undefined‘.
error TS2322 Type ‘string null‘ is not assignable to type ‘string undefined‘.
91 1
|
6月前
|
人工智能 自然语言处理 语音技术
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
52 0
|
6月前
|
C++
std::string 不能跨dll的一种解决方法
std::string 不能跨dll的一种解决方法
|
6月前
|
C++
MFC exe使用C++ dll中的std::string 崩溃
MFC exe使用C++ dll中的std::string 崩溃
VC7(VS2002)调试时 std::string 超过15字符乱码问题
VC7(VS2002)调试时 std::string 超过15字符乱码问题
|
6月前
|
XML 数据格式
解决 Cannot convert value of type ‘java.lang.String‘ to required type ‘java.sql.Driver‘ for property ‘
解决 Cannot convert value of type ‘java.lang.String‘ to required type ‘java.sql.Driver‘ for property ‘
123 0