是否有“分支"?字符串格式描述符? [英] Is there a "branching" string format descriptor?
本文介绍了是否有“分支"?字符串格式描述符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我就是这样做的
printf( (n==0) ? " %d" : " %3d", n );
但是有条件格式描述符吗?
but is there a conditional format descriptor?
所以,它的意思是如果这是很短的使用这样那样的填充,但是,如果这是更长的使用这样那样的填充."
可以吗?
推荐答案
没有条件,但您可以使用 * 指定参数中的宽度.例如:
There's no conditional, but you can use * to specify the width in the arguments. e.g.:
printf(" %*d", (n==0)?1:3, n);
这篇关于是否有“分支"?字符串格式描述符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文