没有与这些操作数匹配的运算符

没有与这些操作数匹配的运算符

#include <iostream>
<span style="background-color: rgb(102, 255, 153);">//#include <string> 缺少这句将会报错</span>。
using namespace std;
class Student
{
public:
	void get_value()
	{
		cout<<"please key num(001-999),name,sex(M/F):";
		cin>>num>>name>>sex;
	}
	void display()
	{
		cout<<"num: "<<num<<endl; 

		cout<<"name: "<<name<<endl; //name定义了字符串变量
		cout<<"sex: "<<sex<<endl;
	}
private:
	int num;
	string name; //name定义了字符串变量
	char sex;
};
class Student1:public Student
{
public:
	void get_value1()
	{
		cout<<"please input age and addr: ";
		cin>>age>>addr;
	}
	void display_1()
	{
		cout<<"age: "<<age<<endl;
		cout<<"address: "<<addr<<endl;
	}
private:
	int age;
	string addr;
};
int main()
{
	Student1 stud;
	stud.get_value();
	stud.get_value1();
	stud.display();
	stud.display_1();
	system("pause");
	return 0;
}



1>------ 已启动生成: 项目: e5.1, 配置: Debug Win32 ------
1>生成启动时间为 2016/7/10 22:38:16。
1>InitializeBuildStatus:
1>  正在创建“Debug\e5.1.unsuccessfulbuild”,因为已指定“AlwaysCreate”。
1>ClCompile:
1>  e5_1.cpp
1>d:\visual studio 2010\projects\e5.1\e5.1\e5_1.cpp(10): error C2678: 二进制“>>”: 没有找到接受“std::basic_istream<_Elem,_Traits>”类型的左操作数的运算符(或没有可接受的转换)
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          d:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1053): 可能是“std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char *)”
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          d:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1060): 或       “std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char &)”
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          d:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1067): 或       “std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,unsigned char *)”
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          d:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1074): 或       “std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,unsigned char &)”
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          d:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(1097): 或       “std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)”
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]

发布了444 篇原创文章 · 获赞 198 · 访问量 92万+
展开阅读全文

c++ 有多个运算符+与这些操作数匹配

04-26

#include<iostream> using namespace std; template<typename T> class vector1{ public: int size; T *v; vector1(int size); ~vector1(); T &operator [](int i)const; template<typename T> friend vector1 operator +(const vector1<T>&c1,const vector1<T>&c2); template<typename T> friend vector1 operator -(const vector1<T>&c1,const vector1<T>&c2); template<typename T> friend vector1 operator -(const vector1<T>&c); template<typename T> friend ostream& operator <<(ostream &out,const vector1<T>&c); template<typename T> friend istream &operator >>(istream &in,vector1<T>&c); }; template<typename T> vector1<T>::vector1(int len){ if(len<=0) exit(0); v=new T[len]; size=len; for(int i=0;i<len;i++) v[i]=0; } template<typename T> vector1<T>::~vector1(){ delete []v; v=NULL; size=0; } template<typename T> T &vector1<T>::operator [](int i)const{ return v[i]; } template<typename T> vector1<T> operator +(const vector1<T>&c1,const vector1<T>&c2){ int len=c1.size; vector1<T>c3(len); for(int i=0;i<len;i++){ c3[i]=c1[i]+c2[i]; } return c3; } template<typename T> vector1<T> operator -(const vector1<T>&c1,const vector1<T>&c2){ int len=c1.size; vector1<T>c3(len); for(int i=0;i<len;i++){ c3[i]=c1[i]-c2[i]; } return c3; } template<typename T> vector1<T> operator -(const vector1<T>&c){ int len1=c.size; for(int i=0;i<len1;i++){ c[i]=-c[i]; } return c; } template<typename T> istream &operator >>(istream &in,vector1<T>&c){ int len1=c.size; for(int i=0;i<len1;i++){ in>>c[i]; } return in; } template<typename T> ostream& operator <<(ostream &out,const vector1<T>&c){ int len1=c.size; out<<"("; for(int i=0;i<len1;i++){ out<<c[i]; if(i<len1-1) out<<","; } out<<")"<<endl; return out; } int main() { vector1<int>c1(10),c2(10),c4(10); cin>>c1>>c2; c4=c1+c2; cout<<c1<<endl; return 0; } ![图片说明](https://img-ask.csdn.net/upload/201504/26/1430024663_278537.png) 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览