C++ have some manipulators : setw(int w), setprecision (int d), setiosflags (long f) resetiosflags (long f), endl ...
the manipulator is just function. Did you know that?? ( I didn't know that.)
In my case, I used endl unconsciously. (별생각없이를 적고 싶은데....내일 찾아보자.)
cout which it use for display on screen, is object of ostream.
cout << "Hello, world"; cout << endl;
Above statement can change below statement.
cout.operator<< ("Hello, world"); cout.operator<< (endl);
that means << operator overloading.
ostream& operator<< (ostream& (*fn) (ostream &) ); { return (*fn)(*this); }
Did you see that? The argument is function pointer!!!!!!
endl is function. endl function is below.
ostream& endl (ostream &stream) { stream << "\n"; return stream; }
In conclusion,
cout << endl;
1.
cout.operator<< (endl);2.
operator<< ( ostream& (*fn) (ostream& stream) ) { return (*fn)(*this);//*fn --> endl }3.
ostream& endl (ostream &stream) { stream << "\n"; return stream; }
That is endl internal operation.
I'm sorry. my english is not good.
Please, understand this.
In my case, this operation is really fun and interesting.
Thanks^^
반응형
'개발' 카테고리의 다른 글
JCO ~ 자바 컨퍼런스!!! (0) | 2012.02.17 |
---|---|
The concept of malloc, free function (0) | 2010.03.18 |
__cplusplus_4 (0) | 2009.08.12 |
ISP mode error (0) | 2009.08.06 |
C 에서 C++ 메소드 호출 하기~ (0) | 2009.08.04 |