int x = 7;
printf("%03d", x); //补0凑齐3位
输出:007
printf("%02d", x); //补0凑齐2位
输出:07
printf("%3d", x); //补空格,凑齐3位
输出:空格空格7
printf("%d", x); //不补位,输出有效位
输出:7
c/c++printf outputs the specified width. If there are not enough digits, use 0 to fill in the output.
Guess you like
Origin blog.csdn.net/m0_51233386/article/details/134476000
Recommended
Ranking