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
Post a Comment