#include <iostream> #include <sstream> #include <string> using std::cout; using std::ostream; //endl是操作算子,LZ可以定义自己的endl覆盖std中的; ostream & endl(ostream & os) { cout<<"my endl\n"; return os; }//在这里面干自己想干的事 void main() { cout<<"test :"<<endl; }
cout<<"test :"<<endl; /*一般操纵算子,内部应该是这样实现的: ostream & ostream::operator<<(ostream &(*pf)(ostream & os) { return (*pf)(*this); } 所以endl其实是个函数指针*/
#define endl "hello \r\n" int main(int argc , char* arcv[]) { cout<<endl; system("pause"); return EXIT_SUCCESS; }
5
3
class xstream : public ostringstream { public: // Constructors, etc. // ........ inline xstream& endl( xstream & ) { xstream << "Hello!"; return (xstream&)ostream::endl(xstream); } // ........ // Insertions for other types };