1. 程式人生 > >C++ 二維座標點運算子過載

C++ 二維座標點運算子過載

#include <iostream> 
using namespace std;
class Point {
private:
	int x;
	int y;
public:
	Point() { };
	friend ostream& operator<< (ostream& os, const Point& P)
	{
		return os << P.x << ","<<P.y;
	};
	friend istream& operator>> (istream& os, Point& P)
	{
		os >> P.x >> P.y;
		return os;
	};



};
int main()
{
	Point p;
	while (cin >> p) {
		cout << p << endl;
	}
	return 0;
}