#include <iostream>
using namespace std;
ostream& fun(ostream& os){
os<<"hello"<<endl;
return os;
}
int main(){
cout<<fun<<"success"<<endl;// operator <<(cout,fun){ fun(os);}
cout<<(void*)fun;
}
输出:
- ostream& operator<< (ostream& (*pf)(ostream&));
经查阅,详情:http://www.cplusplus.com/reference/ostream/ostream/operator<</
上面是一个成员函数 所以省略了ostream&
参数是个函数指针,返回ostream&,接受一个ostram&参数;
摘取:
Calls pf(*this)
, where pf may be a manipulator.
Manipulators are functions specifically designed to be called when used with this operator.
This operation has no effect on the output sequence and inserts no characters (unless the manipulator itself does, like endl or ends do).
这个操作对输出序列无影响,除非操作符自己输出endl或者ends