I/O Manipulators with Parameters - 2
- Generic overload of output operator
template < class F > // function class
std::ostream& operator<< (std::ostream& os, F f) // function object
{
f(os); // apply f.operator() to os
return os;
}
Analogous generic overload of input operator
template < class F >
std::istream& operator>> (std::istream& is, F f)
{
f(is);
return is;
}