注册 登录
编程论坛 C++教室

关于c++ printf 的问题

sorebas 发布于 2011-10-23 17:24, 802 次点击
printf("Zhangsan told a %d.\n. ",a?"truth":"lie");
printf("Lisi told a %d.\n",b?"truth":"lie");
printf("Wangwu told a %d.\n",c?"truth":"lie");

这个如果想改在c++上使用,应该怎么改呢?
我想在网上找,但因为好像搜索引擎不认
?:吧??
我实在没能找到,希望有人能够帮我。。。
5 回复
#2
nomify2011-10-23 17:36
%d 改为%s
#3
lucky5635912011-10-24 09:14
C++没有printf,改为cout
#4
a3733392052011-10-24 21:35
回复 楼主 sorebas
#include <cstdio>
记得加头文件,然后其他的跟C语言一样了
还有,如果你的true和false没有宏定义过的话,前面的%d用%s

[ 本帖最后由 a373339205 于 2011-10-24 21:37 编辑 ]
#5
rqh6564185102011-10-24 21:37
将 %d 改为 %s ,printf 不用改,因为C++兼容C
#6
sorebas2011-10-24 22:45
谢谢楼上的朋友.

1