重载类Pointed的运算符“<<”和“>>”,并测试该运算符。
#include "stdafx.h"
#include <iostream>
using namespace std;
class Pointed
{
private:
int x;
int y;
public:
Pointed(int x1=0,int y1=0)
{
this->x = x1;
this->y = y1;
}
friend istream & operator >> (istream &in, Pointed &p)
{
in >> p.x >> p.y;
return in;
}
friend ostream & operator << (ostream &out, Pointed &p)
{
out << "x=" << p.x << '\n' <<"y=" <<p.y;
return out;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Pointed p(2,4);
cout << p << endl;
cout << "Input int a and int b:";
cin >> p;
cout << p <<endl;
return 0;
}