黑马程序员技术交流社区

标题: 是否必须写#include<stdio.h>有关问题 [打印本页]

作者: 王海江1    时间: 2014-6-14 20:42
标题: 是否必须写#include<stdio.h>有关问题
我记得以前在书上看到说:当调用printf和scanf函数时可以不写#include<stdio.h>,,,,但调用put char、gets等函数时必须写#include<stdio.h>,,,,时这样吗????
作者: huangqiwa    时间: 2014-6-15 10:03
当然不是这样,printf也是库函数,你不写,那printf从哪里来呢?又不是自己写的
这种问题建议楼主直接动手,实践出真理!何必在群里问!多简单,直接敲一个printf就可以了!
作者: chain    时间: 2014-6-15 11:29
这个东西在文件包含里面有详细介绍啊,深刻的理解他
作者: 张宇清    时间: 2014-6-15 11:50
  1. _CRTIMP size_t __cdecl fwrite(const void *, size_t, size_t, FILE *);
  2. _CRTIMP int __cdecl getc(FILE *);
  3. _CRTIMP int __cdecl getchar(void);
  4. _CRTIMP int __cdecl _getmaxstdio(void);
  5. _CRTIMP char * __cdecl gets(char *);
  6. _CRTIMP int __cdecl _getw(FILE *);
  7. _CRTIMP void __cdecl perror(const char *);
  8. _CRTIMP int __cdecl _pclose(FILE *);
  9. _CRTIMP FILE * __cdecl _popen(const char *, const char *);
  10. _CRTIMP int __cdecl printf(const char *, ...);
  11. _CRTIMP int __cdecl putc(int, FILE *);
  12. _CRTIMP int __cdecl putchar(int);
  13. _CRTIMP int __cdecl puts(const char *);
复制代码


看了一下stdio.h的源码,可以看到 stdio.h函数就是提供输入输出函数的声明的,如果不包含的话,是不能使用诸如printf和scanf这样的输入输出函数的。
作者: lewisen    时间: 2014-6-15 12:06
1.概念:库函数是有C系统提供给用户的不需用户定义,也不用在程序中声明,只需在程序前包含该函数的头文件,即可在程序中调用,如printf、scanf、getchar、gets等均属于此类,所以必须包含头文件才可使用。
2.像楼主类似的问题,可以在x-code中输入输出试一下,实践是检验真理的标准嘛!

作者: Emy♪    时间: 2014-6-16 10:15
include stdio.h非必需。stdio.h定义了不少输入输出的标准函数比如说printf,大部分程序都会用上,所以你感觉好像必须有了。

有些程序不需要任何标准输入输出语句,比如说单片机上的程序。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2