I/O Manipulators with Parameters - 4
os << SetWidth(8) << x;
Sequence of events:
- temporary SetWidth(8) object created (call it "temp")
- operator<< called with arguments (os, temp)
- temp(os) called, that is:
- temp.operator() called with argument os
- os.width(8) called
- object temp goes out of scope
- operator<< returns reference to os for application of os << x
Can also be applied to input:
is >> SetWidth(20) >> y;
|