Unfortunately, no. You must use setw()
before almost every output operation. The problem is that operator<<
effectively calls setw(0)
after the output, thus you need to set width again. See here for a full list of operations that reset field width.
Note: setw
is just a wrapper around width()
, so using the latter won't help.