The width is a special formatting setting: While all other formatting flags are stick, the width()
will be reset by each output operator (well, you can have user-defined output operators which don't reset the width()
but doing so would not follow the normal style). That is, you need to set the width immediately prior to the output that should be affected:
std::cout << std::setfill('0')
<< std::setw(2) << hour << ':'
<< std::setw(2) << min << ' ';