印刷'%'在C / C ++的printf [英] Printing '%' with printf in C/C++

查看:134
本文介绍了印刷'%'在C / C ++的printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  如何逃脱%标志在C&rsquo的;?s的printf


这必须是一个简单的问题,但我找不到我的书上或网上的答案;如何在C打印'%'?

例如:

 的printf(A:%.2f%,PC);

...失败,则编译器抱怨有一个无效的转换。当然,一个简单的方法是;

 的printf(A:%.2f%C,PC,'%');

但它是相当不雅...

我看了我发现没有%转义序列在网络上,我以为\\%会工作,但它的作用。


解决方案

 的printf(A:%.2f %%,PC);

Possible Duplicate:
How to escape the % sign in C’s printf?

This has to be an easy question but I can't find the answer on my book or the web; how to print '%' in C ?

e.g.:

printf("A: %.2f%", pc);

...fails, the compiler complains there is an invalid conversion. Of course an easy way is;

printf("A: %.2f%c", pc, '%');

But it's rather inelegant...

I looked on the web I found no escape sequence for %, I thought \% would work but it does.

解决方案

printf("A: %.2f%%", pc);

这篇关于印刷'%'在C / C ++的printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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