To provide an inline formatting mechanism. The basic template for parameterless manipulators is shown in the listing below.
ostream &manip-name(ostream &stream) { // coding return stream; }
Use overloaded manipulators to provide specific and unique formatting methods relative to one class.
A reference to ostream. (Usually the this pointer.)
<iomanip> for manipulators with parameters
#include <iostream> using namespace std; ostream &rJus(ostream &stream); int main() { cout << "align right " << rJus << "for column"; return 0; } ostream &rJus(ostream &stream) { stream.width(30); stream.setf(ios::right); return stream; }
Result:
align right for column