Problem Description
建立一个二维坐标系的类TwoCoor,用x、y表示坐标值,重载输入/输出运算符,使之能够直接输入/输出坐标点的坐标值。
//你的代码将被嵌在这里
int main(){
TwoCoor p;
cin>>p;
cout<<"点p是:"<<p;
return 0;
}
Sample Input
-3 6
Sample Output
点p是:(-3,6)
#include <iostream>
using namespace std;
class TwoCoor
{
public:
int m_x;
int m_y;
};
ostream& operator<<(ostream& out, TwoCoor& p)
{
out << "(" <<p.m_x << "," << p.m_y << ")" << endl;
return out;
}
istream& operator>>(istream& ci, TwoCoor& p)
{
ci >> p.m_x >> p.m_y;
return ci;
}