作者:凰千寻_847 | 来源:互联网 | 2023-05-18 07:12
Ihavesomenumbersofdifferentlength(like1,999,76492,soon)andIwanttoconvertthemallt
I have some numbers of different length (like 1, 999, 76492, so on) and I want to convert them all to strings with a common length (for example, if the length is 6, then those strings will be: '000001', '000999', '076492').
我有一些不同长度的数字(比如1,999,76492等等),我想把它们都转换成具有相同长度的字符串(例如,如果长度是6,那么这些字符串将是:'000001','000999','076492')。
In other words, I need to add correct amount of leading zeros to the number.
换句话说,我需要在数字中加入正确数量的前导0。
int n = 999;
string str = some_function(n,6);
//str = '000999'
Is there a function like this in C++?
c++中有这样的函数吗?
7 个解决方案