到底哪出了问题? 谁来帮帮我啊,郁闷啊
以下程序究竟哪出了问题,谁来帮帮我,谢了!
#include <iostream.h>
#include <istream.h>
#include <ostream.h>
#include <string.h>
class Worker{
public:
char name[20];
int id;
float wage;
istream& operator>>(istream& istr, Worker& x)
{
istr>>x.name>>x.id>>x.wage;
return istr;
}
ostream& operator<<(ostream& ostr, Worker& x)
{
ostr<<x.id<<" "<<x.name<<" "<<x.wage<<endl;
return ostr;
}
Worker(int i,char *nam,float wag)
{
id=i;
strcpy(name,nam);
wage=wag;
}
Worker()
{
}
};
void main()
{
Worker worker;
cin>>worker;
cout<<worker;
}
提示出错如下:
1. error C2804: binary 'operator >>' has too many parameters
2. error C2333: '>>' : error in function declaration; skipping function body
3. error C2804: binary 'operator <<' has too many parameters
4. error C2333: '<<' : error in function declaration; skipping function body
5. error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class Worker' (or there is no acceptable conversion)
6. error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Worker' (or there is no acceptable conversion)
Error executing cl.exe.