I/O Manipulators with Parameters - 3
// manipulator for setting width
class SetWidth
{
public:
SetWidth(int width) : width_(width)
{}
void operator() (std::ios_base& s)
{
s.width(width_);
}
private:
int width_;
};
// useage:
os << SetWidth(8) << x;
is >> SetWidth(8) >> y;