For faster navigation, this Iframe is preloading the Wikiwand page for stdio.h.

stdio.h

stdio.h(英语:standard input/output header,标准输入/输出头文件)是C语言为输入输出提供的标准库头文件,其前身是迈克·莱斯克20世纪70年代编写的“可移植输入输出程序库”[1]

C语言中的所有输入和输出都由抽象的字节流来完成,对文件的访问也通过关联的输入或输出流进行。这一模式随UNIX操作系统而普及,在现代操作系统和编程语言中仍被广泛应用。

头文件内容

[编辑]

类型

[编辑]
标识符 说明
size_t 用于表示大小的数据类型
FILE 记录流的资讯的数据结构
fpos_t 用于在文件中定位的数据类型

[编辑]
标识符 说明
NULL 空指针
_IOFBF 用于控制缓冲方式的参数
_IOLBF
_IONBF
BUFSIZ setbuf函数使用的缓冲区大小
EOF 文件结尾标志
FOPEN_MAX 实现保证能够同时打开的文件数量
FILENAME_MAX 实现保证支持的最长文件名的字符数
L_tmpnam 存放tmpnam函数生成的临时文件名的char数组的大小
SEEK_CUR 用于控制文件定位方式的参数
SEEK_END
SEEK_SET
TMP_MAX 实现保证能生成的临时文件名个数

标准流

[编辑]
标识符 说明
stderr 标准错误流
stdin 标准输入流
stdout 标准输出流

函数

[编辑]
类型 函数原型
文件操作 int remove(const char *filename);
int rename(const char *old, const char *new);
FILE *tmpfile(void);
char *tmpnam(char *s);
int fclose(FILE *stream);
int fflush(FILE *stream);
FILE *fopen(const char * restrict filename, const char * restrict mode);
FILE *freopen(const char * restrict filename, const char * restrict mode, FILE * restrict stream);
void setbuf(FILE * restrict stream, char * restrict buf);
int setvbuf(FILE * restrict stream, char * restrict buf, int mode, size_t size);
格式化输入输出 int fprintf(FILE * restrict stream, const char * restrict format, ...);
int fscanf(FILE * restrict stream, const char * restrict format, ...);
int printf(const char * restrict format, ...);
int scanf(const char * restrict format, ...);
int snprintf(char * restrict s, size_t n, const char * restrict format, ...);
int sprintf(char * restrict s, const char * restrict format, ...);
int sscanf(const char * restrict s, const char * restrict format, ...);
int vfprintf(FILE * restrict stream, const char * restrict format, va_list arg);
int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg);
int vprintf(const char * restrict format, va_list arg);
int vscanf(const char * restrict format, va_list arg);
int vsnprintf(char * restrict s, size_t n, const char * restrict format, va_list arg);
int vsprintf(char * restrict s, const char * restrict format, va_list arg);
int vsscanf(const char * restrict s, const char * restrict format, va_list arg);
字符输入输出 int fgetc(FILE *stream);
char *fgets(char * restrict s, int n, FILE * restrict stream);
int fputc(int c, FILE *stream);
int fputs(const char * restrict s, FILE * restrict stream);
int getc(FILE *stream);
int getchar(void);
int putc(int c, FILE *stream);
int putchar(int c);
int puts(const char *s);
int ungetc(int c, FILE *stream);
直接输入输出 size_t fread(void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream);
size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream);
文件内定位 int fgetpos(FILE * restrict stream, fpos_t * restrict pos);
int fseek(FILE *stream, long int offset, int whence);
int fsetpos(FILE *stream, const fpos_t *pos);
long int ftell(FILE *stream);
void rewind(FILE *stream);
错误处理 void clearerr(FILE *stream);
int feof(FILE *stream);
int ferror(FILE *stream);
void perror(const char *s);

相关库

[编辑]

C++引入了iostream进行输入输出,但仍保留了stdio.h的功能。

贝尔实验室开发了Sfio库,旨在弥补stdio.h在功能、速度和安全性上的不足。[2]

参见

[编辑]

参考文献

[编辑]
  1. ^ Kernighan, Brian; Pike, Rob. The UNIX Programming Environment. Englewood Cliffs: Prentice Hall. 1984: 200. 
  2. ^ Korn, David G.; Vo, Kiem-Phong. SFIO: Safe/Fast String/File IO. Proc. Summer USENIX Conf. 1991. 

外部链接

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
stdio.h
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?