【原】error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
2014-05-22 15:29
429 查看
今天遇到一个非常难以排查的BUG,谷歌度娘都问过了依旧无解,最后自己重新尝试之后找到解决方案:
先看一下报错信息:
网上搜了一下,很多人说是因为没有#include <string>的缘故,但是反复确认后发现我有做到。百思不得其解,还一度以为是不同文件的头文件重复引用导致<string>失效,但是这条说不通!后面冷静了之后,双击错误信息查看源码,发现基本上这些错误含有两个特征:
1.都是LOG4CPLUS_DEBUG等调试函数
2.参数都有string类型
然后我单独写了一小段程序验证了一下,好家伙,真是这样子。原来,LOG4CPLUS_DEBUG函数不能直接打印string对象,只支持其转换形式.c_str()。
解决方法:把所有的LOG4CPLUS_DEBUG函数中的string加个c_str()
先看一下报错信息:
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> ] ......//一行出错后就会有一堆这样的With[]....出现,非常烦
网上搜了一下,很多人说是因为没有#include <string>的缘故,但是反复确认后发现我有做到。百思不得其解,还一度以为是不同文件的头文件重复引用导致<string>失效,但是这条说不通!后面冷静了之后,双击错误信息查看源码,发现基本上这些错误含有两个特征:
1.都是LOG4CPLUS_DEBUG等调试函数
2.参数都有string类型
然后我单独写了一小段程序验证了一下,好家伙,真是这样子。原来,LOG4CPLUS_DEBUG函数不能直接打印string对象,只支持其转换形式.c_str()。
解决方法:把所有的LOG4CPLUS_DEBUG函数中的string加个c_str()
相关文章推荐
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_s
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring'
- 错误 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::str
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring'
- C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::basic
- Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Stude
- error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::
- C++,如何输出string类型的数据(报错:no operator defined which takes a right-hand operand of type 'class std::bas)
- 解决 C++错误 error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no
- error C2679: binary '<<' : no operator found 解决办法
- error C2678 binary '<' : no operator found for map<std::string, shared_ptr<Foo>>
- error C2677: binary '-' : no global operator defined which takes type 'class CString' (or there is n
- could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
- Error 42 error C2784: 'bool std::operator <(const std::_Tree<_Traits>
- error: A1355U: A Label was found which was in no AREA 终级解决办法