标题:[求助]自己的inserter和extractor 实在不明白错在何处
取消只看楼主
realoneyjw
Rank: 1
等 级:新手上路
帖 子:99
专家分:0
注 册:2005-5-13
 问题点数:0 回复次数:0 
[求助]自己的inserter和extractor 实在不明白错在何处

创建了自己的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.

搜索更多相关主题的帖子: extractor inserter 
2005-10-08 21:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-29608-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014675 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved