cout과 endl 이해하기

cout 은 ostream 객체이다.

<< 연산자가 overloading 되어 출력처럼 사용된다.

cout << endl;
// cout.operator<<(endl); 처럼 해석된다.

<<, >> 연산자의 오버로딩

cout << pos //이것이 가능하기 위해서는 << 연산자가 오버로딩 되어 있어야한다.
//cout.operator<<(pos) or operator<<(cout, pos) 가 가능하다.
//cout 에 멤버함수를 만드는건 불가능하기 떄문에 전역함수 오버로딩을 선택한다.
int main(void)
{
	Point pos(3, 4);
	cout << pos << endl; // [3, 4] 출력!
}
...
ostream& operator<<(ostream& os, const Point& pos)
{
	os << pos.xpos << pos.ypos << endl;
}