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;
}

猜你喜欢

转载自blog.csdn.net/wwxy1995/article/details/82833526
今日推荐