在C中使用printf时如何转义%符号?
printf("hello\%"); /* not like this */
在C中使用printf时如何转义%符号?
printf("hello\%"); /* not like this */
当前回答
你可以使用%%:
printf("100%%");
结果是:
100%
其他回答
是这样的:
printf("hello%%");
//-----------^^ inside printf, use two percent signs together
C语言中的反斜杠用于转义字符串中的字符。字符串不会将%识别为特殊字符,因此不需要转义。Printf则是另一回事:使用%%来打印一个%。
你可以使用%%:
printf("100%%");
结果是:
100%
是的,使用printf("hello%%");做完了。
双字符“%”也适用于“. format(…)”。 示例(iDrawApertureMask == 87, fCornerRadMask == 0.05): csCurrentLine.Format(“\ %添加% 2 d C %, % 6.4 f * \ %”,iDrawApertureMask, fCornerRadMask); 给出csCurrentLine中(字符串内容)的期望值和期望值; “% ADD87C, 0.0500 * %”