标题:&怎么用的
取消只看楼主
换空依晨
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2013-9-13
结帖率:30.77%
 问题点数:0 回复次数:1 
&怎么用的
程序代码:
#include"iostream.h"
class cstudent
{
public:
friend ostream& operator<<(ostream& os,cstudent stu);
friend istream& operator>>(istream& is,cstudent& stu);
private:
char strname[10];
char strid[10];
int fscore[3];
};
ostream& operator<<(ostream &os,cstudent stu)
{
os<<endl<<"请输入学生信息:"<<endl<<"姓名"<<stu.strname<<endl<<"学号"<<stu.strid<<endl;
os<<"三门成绩为:"<<stu.fscore[0]<<"\t"<<stu.fscore[1]<<"\t"<<stu.fscore[2]<<endl;
return os;
}
istream& operator>>(istream& is,cstudent& stu)
{
cout<<"请输入学生信息:"<<endl<<"姓名";
is>>stu.strname;
cout<<"学号:";
is>>stu.strid;
cout<<"三门成绩";
is>>stu.fscore[0]>>stu.fscore[1]>>stu.fscore[2];
return is;
}
void main()
{
cstudent one ;
cin>>one;
cout<<one;
}

friend ostream& operator<<(ostream& os,cstudent stu);
friend istream& operator>>(istream& is,cstudent& stu);这两个定义为什么不一样 ,多了个& ,还有这里面的所有&的位置到底是怎么放的 怎么书上有放在左 放在右 ,但是我换个位置 编译没错误 运行就不行啊
2014-03-04 20:04
换空依晨
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2013-9-13
得分:0 
回复 2楼 rjsp
friend ostream& operator<<(ostream& os,cstudent stu);
friend istream& operator>>(istream& is,cstudent& stu);为什么这两个友元定义不一样  下边的怎么多了个&
2014-03-05 10:03



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




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

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