c++ - Number to string with fixed length -


is there function in standard library work std::to_string, fixed length?

std::cout << formatted_time_string << ":" << std::to_string(milliseconds) << " ... other stuff" << std::endl; 

in example above, milliseconds range 1 3 digits , therefore output improperly formatted.

i know there lot of other options how (e.g. sprintf, calculating length etc.), inline option nice have.

try use setw() format output.

std::out << setw(3) << formatted_time_string << ":" << std::to_string(milliseconds) 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -