#include<iostream.h>
#include<iomanip.h>
class person
{
int a,b,c;
public:
person(int x=1,int y=2,int z=3):a(x),b(y),c(z){};
friend ostream & operator << (ostream &s,person p);
friend istream & operator >> (istream &s,person p);
};
ostream & operator <<(ostream &s,person p)
{
cout<<p.a<<endl<<p.b<<endl<<p.c<<endl;
return s;
}
istream & operator >>(istream &s,person p)
{
cin>>p.a>>p.b>>p.c;
return s;
}
int main()
{
person p;
cin>>p;
cout<<p;
return 0;
}
C++重载">>"的小问题
答案:1 悬赏:80 手机版
解决时间 2021-08-23 17:27
- 提问者网友:战皆罪
- 2021-08-23 09:20
最佳答案
- 五星知识达人网友:怀裏藏嬌
- 2021-08-23 09:49
//粗体为修改部分:
#include<iostream.h>
#include<iomanip.h>
class person
{
int a,b,c;
public:
person(int x=1,int y=2,int z=3):a(x),b(y),c(z){};
friend ostream & operator << (ostream &s,person p);
friend istream & operator >> (istream &s,person &p);
};
ostream & operator <<(ostream &s,person p)
{
s<<p.a<<endl<<p.b<<endl<<p.c<<endl;
return s;
}
istream & operator >>(istream &s,person &p)
{
s>>p.a>>p.b>>p.c;
return s;
}
int main()
{
person p;
cin>>p;
cout<<p;
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯