创建了自己的inserter和extractor,但是有两处错误,实在没有想明白,求教于各位大侠 还望指点一二,小弟不甚感激。代码及出错信息如下: #include<iostream> using namespace std;
class stu { public: int num; char name[30]; float score; stu(){} friend ostream &operator>>(ostream &stream,stu obj); friend istream &operator<<(istream &stream,stu &obj); };
ostream &operator>>(ostream &stream,stu obj) { cout<<"No.\t"<<"Name\t"<<"Score"<<endl; stream<<obj.num<<"\t"; stream<<obj.name<<"\t"; stream<<obj.score<<endl; return stream; }
istream &operator<<(istream &stream,stu &obj) { cout<<"Enter the number:"<<endl; stream>>obj.num; cout<<"Enter the name:"<<endl; stream>>obj.name; cout<<"Enter the score:"<<endl; stream>>obj.score; return stream; }
int main() { stu a; cin>>a; cout<<a; return 0; } error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class stu' (or there is no acceptable conversion) error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class stu' (or there is no acceptable conversion) Error executing cl.exe.