重载运算符
#include<iostream.h>
//using namespace std;
class point{
public:int x,y;
public:
point() {x=0;y=0;}
point(int xx,int yy) {x=xx;y=yy;}
friend ostream &operator<<(ostream &output,point obj);
friend istream &operator>>(istream &input,point &obj);
};
ostream &operator<<(ostream &output,point obj) {
output<<"x="<<obj.x<<" "<<"y="<<obj.y<<endl;
return output;
}
istream &operator>>(istream &input,point &obj) {
cout<<"请输入x、y的值"<<endl;
input>>obj.x>>obj.y;
return input;
}
int main() {
point p(10,20);
cout<<p;
cin>>p;
cout<<p;
return 0;
}