&是什么QUOT;%6D"意味着的printf [英] What does "%.6d" mean in printf

查看:255
本文介绍了&是什么QUOT;%6D"意味着的printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么%6D 意味着:

 的printf(%s%6D LEN:%D,TIMESTR,报头 - > ts.tv_usec,报头 - > LEN);

它是一个错字?

这似乎%。6D 相同%6D


解决方案

 %。6D


  

precision 作为整数说明符(D,I,O,U,X,X),precision指定的最小位数格式写入。如果要写入的值大于这个数短,结果为带前导零填充。该值不会被截断,即使结果是不再


 %6D


  

的宽度(此处6)指定要打印的字符的最小数目。如果要打印的值大于此数短,结果是<强>使用空格填充。该值不会被截断,即使结果是较大的。


例如:

 的printf(%6D \\ N%6D,1,1);

输出:

  000001
     1

What does %.6d mean in:

printf("%s.%.6d len:%d ", timestr, header->ts.tv_usec, header->len);

Is it a typo?

It seems %.6d is the same as %6d.

解决方案

%.6d

In the .precision format for integer specifiers (d, i, o, u, x, X), precision specifies the minimum number of digits to be written. If the value to be written is shorter than this number, the result is padded with leading zeros. The value is not truncated even if the result is longer.

%6d

The width (here 6) specifies the minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is not truncated even if the result is larger.

Example:

printf("%.6d\n%6d",1,1);

outputs:

000001
     1

这篇关于&是什么QUOT;%6D&QUOT;意味着的printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆