error C2679: binary '<<' : no operator found 解决办法
来源:互联网 发布:jpz45加强后数据105炮 编辑:程序博客网 时间:2024/06/06 00:25
自己做了个小例子,编译未通过,代码如下:
#include <iostream>#include <stdlib.h>using namespace std;class Student{public:void setName(string _Name){m_strName = _Name;}string getName(){return m_strName;}void InitScore(){m_iscore = 0;}int getScore(){return m_iscore;}void Study(int _score){m_iscore += _score;}string m_strName;int m_iscore;};int main(void){Student m_std;m_std.InitScore();m_std.setName("zhangshan");m_std.Study(4);//语文cout << m_std.getName() << m_std.getScore() << endl;m_std.Study(6);cout << m_std.getName() << m_std.getScore() << endl;return 0;}
编译出错如下:
f:\study file\training\fengzhuang\fengzhuang1\fengzhuang.cpp(43) : 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 (x86)\microsoft visual studio 9.0\vc\include\ostream(653): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(700): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(738): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(785): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(909): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(916): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(923): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(930): or 'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(170): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(176): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(183): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(190): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(210): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(243): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(263): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 int)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(288): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned int)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(308): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(328): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned long)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(349): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(369): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(390): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(410): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(430): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(450): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> d:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(470): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'1> with1> [1> _Elem=char,1> _Traits=std::char_traits<char>1> ]1> while trying to match the argument list '(std::ostream, std::string)'
解决办法:
增加头文件:#include <string>
阅读全文
0 0
- error C2679: binary '<<' : no operator found 解决办法
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring'
- 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::string'
- error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring'
- 错误1error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::str
- Error1error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::
- C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::basic
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Stude
- 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 '>>'
- vs2010 error c2679 binary
- 解决 C++错误 error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no
- error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::
- error C2678 binary '<' : no operator found for map<std::string, shared_ptr<Foo>>
- error C2679: binary ',class std::allocator >' (or there is no accept
- error C2679
- POJ 2823 Sliding Window
- DUC
- activeMQ 消息队列 相关配置
- 分布式资源管理器YARN简介(一)
- C语言的一些概念
- error C2679: binary '<<' : no operator found 解决办法
- 十字链表存储稀疏矩阵
- mac下安装face_recognition
- Rootkit/Hook/Binder- Android
- XShell安装
- 使用Keil-STM32,cmsis_os.c 出现 error: #268: declaration may not appear after executable....
- [Array]-643. Maximum Average Subarray I (@python) 解题报告
- Stream API处理集合
- data-toggle与data-target是什么作用