Guus Geurkink Guus Geurkink - 2 months ago 13
C++ Question

Add leading zero's to string, without (s)printf

I want to add a variable of leading zero's to a string.
I couldn't find anything on Google, without someone mentioning (s)printf,
but I want to do this without (s)printf.

Does anybody of the readers know a way?

Answer Source
// assuming that `original_string` is of type `std:string`:

std::string dest = std::string( number_of_zeros, '0').append( original_string);