삽입 연산자(<<)
추출 연산자(>>)
#include <iostream>
#include <iomanip>
using namespace std;
/*
(3,4)
(1,100)(2,200)
*/
class Point {
int x, y;
public:
Point(int x = 0, int y = 0) {
this->x = x;
this->y = y;
}
friend ostream& operator <<(ostream& stream, Point a);
};
ostream& operator <<(ostream& stream, Point a) {
stream << "(" << a.x << "," << a.y << ")";
return stream;
}
int main() {
Point a(3, 4);
cout << a << endl;
Point q(1, 100), r(2, 200);
cout << q << r << endl;
}
#include <iostream>
#include <iomanip>
using namespace std;
/*
x 좌표 >>100
y 좌표 >>200
(100,200)
*/
class Point {
int x, y;
public:
Point(int x = 0, int y = 0) {
this->x = x;
this->y = y;
}
friend ostream& operator <<(ostream& stream, Point a);
friend istream& operator >>(istream& ist, Point &a);
};
ostream& operator <<(ostream& stream, Point a) {
stream << "(" << a.x << "," << a.y << ")";
return stream;
}
istream& operator >>(istream& ist, Point& a) {
cout << "x 좌표 >>";
ist >> a.x;
cout << "y 좌표 >>";
ist >> a.y;
return ist;
}
int main() {
Point p;
cin >> p;
cout << p;
}