printf格式输出数字,位数不够前面补0,适用与输出编号 printf格式输出:%[flags][width][.perc][F|N|h|l]type 用到了flags中的 0 (注意是零不是欧) ,其百科描述为:将输出的前面补上0,直到占满指定列宽为止(不可以搭配使用-) width 即表示需要输出的位数. int a = 4; printf("%03d",a); 输出:004 也可以用 * 代替位数,在后面的参数列表中用变量控制输出位数: int a = 4; int n = 3…
参考:http://www.cplusplus.com/reference/cstdio/printf/ C string that contains the text to be written to stdout.It can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatt…
format 参数输出的格式,定义格式为 %[flags][width][.precision][length]specifier specifier在最后面.定义了数据类型. Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument: speci…