将前导零添加到字符串,不带printf
问题描述:
我要向字符串添加前导零的变量。
我在Google上找不到任何东西,没有人提到printf,
,但我想这样做没有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.
答
// assuming that `original_string` is of type `std:string`:
std::string dest = std::string( number_of_zeros, '0').append( original_string);