鱼C论坛

 找回密码
 立即注册
查看: 1191|回复: 4

[已解决]printf

[复制链接]
发表于 2020-8-14 18:50:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. int main()
  2. {
  3.         int a;
  4.         char b;
  5.         float c;
  6.         double d;
  7.        
  8.         a = 520;
  9.         b = 'A';
  10.         c = 3.14;
  11.         d = 3.141592653;
  12.        
  13.         printf("数字%d\n", a);
  14.         printf("字母%c\n", b);
  15.         printf("单精度浮点数%.2f\n", c);
  16.         printf("双精度浮点数%11.9f\n", d);
  17.        
  18.         return 0;
  19. }
复制代码
照抄小甲鱼课上的代码却出现了如下报错
  1. [Error] 'printf' was not declared in this scope
复制代码

如何解决?

最佳答案
2020-8-14 18:51:22
在文件开头加上一句:

  1. #include <stdio.h>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-14 18:51:22 | 显示全部楼层    本楼为最佳答案   
在文件开头加上一句:

  1. #include <stdio.h>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-14 18:52:46 | 显示全部楼层
  1. #include<stdio.h>


  2. int main()
  3. {
  4.         int a;
  5.         char b;
  6.         float c;
  7.         double d;
  8.         
  9.         a = 520;
  10.         b = 'A';
  11.         c = 3.14;
  12.         d = 3.141592653;
  13.         
  14.         printf("数字%d\n", a);
  15.         printf("字母%c\n", b);
  16.         printf("单精度浮点数%.2f\n", c);
  17.         printf("双精度浮点数%11.9f\n", d);
  18.         
  19.         return 0;
  20. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-14 18:53:41 | 显示全部楼层
zltzlt 发表于 2020-8-14 18:51
在文件开头加上一句:

谢谢,已经解决了,但是您能告诉我下为什么要这样写吗?想理解一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-14 21:19:02 | 显示全部楼层
Simon_xlj 发表于 2020-8-14 18:53
谢谢,已经解决了,但是您能告诉我下为什么要这样写吗?想理解一下

因为代码中的printf被包含在stdio.h文件中,
#include<stdio.h>的意思是包含标准输入输出头文件!
std是standard的缩写,意思是标准!
io是input和putput的缩写,意思是输入输出!
.h是头文件的意思,h是head的缩写!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-1 07:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表