see boost::format or combination std::stringstream::width( 3 ); and stream << std::setfill( '0' );