You can use standard manipulators from <iomanip> , but there is no clear one that does fill and width at the same time:
stream << std::setfill('0') << std::setw(2) << value;
It is easy to write your own object so that when you insert into the stream, both functions are performed:
stream << myfillandw( '0', 2 ) << value;
eg.
struct myfillandw { myfillandw( char f, int w ) : fill(f), width(w) {} char fill; int width; }; std::ostream& operator<<( std::ostream& o, const myfillandw& a ) { o.fill( a.fill ); o.width( a.width ); return o; }
Charles Bailey May 15 '10 at 9:29 a.m. 2010-05-15 09:29
source share