标准库标头 <stdio.h>
来自cppreference.com
此标头是输入/输出库的一部分,提供通用的文件操作支持,还提供用于窄字符的输入/输出函数。
类型
| 对象类型,能够保存控制 C I/O 流所需的全部信息 (typedef) | |
| 非数组完整对象类型,足以唯一指定文件的位置和多字节解析状态 (typedef) |
预定义标准流
与标准输入流关联的 FILE* 类型表达式与标准输出流关联的 FILE* 类型表达式与标准错误输出流关联的 FILE* 类型表达式 (宏常量) |
函数
文件访问 | |
(C11) |
打开文件 (函数) |
(C11) |
以不同名称打开既存的文件流 (函数) |
| 关闭文件 (函数) | |
| 将输出流与实际文件同步 (函数) | |
| 为文件流设置缓冲区 (函数) | |
| 为文件流设置缓冲区和其大小 (函数) | |
直接输入/输出 | |
| 从文件读取 (函数) | |
| 写入到文件 (函数) | |
无格式输入/输出 | |
窄字符 | |
| 从文件流获取一个字符 (函数) | |
| 从文件流获取一个字符串 (函数) | |
| 将一个字符写入文件流 (函数) | |
| 将一个字符串写入文件流 (函数) | |
| 从 stdin 读取一个字符 (函数) | |
(C11 移除)(C11) |
从 stdin 读取一个字符串 (函数) |
| 将一个字符写入 stdout (函数) | |
| 将一个字符串写入 stdout (函数) | |
| 将一个字符送回文件流 (函数) | |
有格式输入/输出 | |
窄字符 | |
(C11)(C11)(C11) |
从stdin、文件流或缓冲区读取格式化输入 (函数) |
(C99)(C99)(C99)(C11)(C11)(C11) |
从 stdin、文件流或缓冲区读取格式化输入 使用可变参数列表 (函数) |
(C99)(C11)(C11)(C11)(C11) |
打印格式化输出到 stdout、文件流或缓冲区 (函数) |
(C99)(C11)(C11)(C11)(C11) |
打印格式化输出到 stdout、文件流或缓冲区 使用可变参数列表 (函数) |
文件定位 | |
| 返回当前的文件位置指示值 (函数) | |
| 获取文件位置指示器 (函数) | |
| 将文件位置指示符移动到文件中的指定位置 (函数) | |
| 将文件位置指示器移动到文件中的指定位置 (函数) | |
| 将文件位置指示器移动到文件首 (函数) | |
错误处理 | |
| 清除错误 (函数) | |
| 检查文件结尾 (函数) | |
| 检查文件错误 (函数) | |
| 显示对应当前错误的字符串到 stderr (函数) | |
对文件的操作 | |
| 删除文件 (函数) | |
| 重命名文件 (函数) | |
(C11) |
返回指向临时文件的指针 (函数) |
(C11) |
返回唯一的文件名 (函数) |
宏常量
EOF |
值为负的 int 类型整数常量表达式 (宏常量) |
FOPEN_MAX |
能同时打开的最大文件数 (宏常量) |
FILENAME_MAX |
保有最长受支持文件名所需的 char 数组大小 (宏常量) |
_PRINTF_NAN_LEN_MAX (C23) |
所有(可能取反的)非数(NaN)值可输出的最大字符数 (宏常量) |
BUFSIZ |
setbuf 所用的缓冲区大小 (宏常量) |
_IOFBF_IOLBF_IONBF |
表示 setvbuf 要设置的缓冲模式(全缓冲/行缓冲/无缓冲) (宏常量) |
SEEK_SETSEEK_CURSEEK_END |
表示 fseek 要用到的偏移原点(文件首/当前位置/文件尾) (宏常量) |
TMP_MAXTMP_MAX_S (C11) |
tmpnam / tmpnam_s 所能生成的独有文件名的最大数量 (宏常量) |
L_tmpnamL_tmpnam_s (C11) |
保有 tmpnam / tmpnam_s 结果所需的 char 数组大小 (宏常量) |
概要
#define __STDC_VERSION_STDIO_H__ 202311L
typedef /* 见描述 */ FILE;
typedef /* 见描述 */ size_t;
typedef /* 见描述 */ FILE;
typedef /* 见描述 */ fpos_t;
#define NULL /* 见描述 */
#define _IOFBF /* 见描述 */
#define _IOLBF /* 见描述 */
#define _IONBF /* 见描述 */
#define BUFSIZ /* 见描述 */
#define EOF /* 见描述 */
#define FOPEN_MAX /* 见描述 */
#define FILENAME_MAX /* 见描述 */
#define L_tmpnam /* 见描述 */
#define SEEK_CUR /* 见描述 */
#define SEEK_END /* 见描述 */
#define SEEK_SET /* 见描述 */
#define TMP_MAX /* 见描述 */
#define stdin /* 见描述 */
#define stdout /* 见描述 */
#define stderr /* 见描述 */
#define _PRINTF_NAN_LEN_MAX /* 见描述 */
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 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);
int fprintf(FILE* restrict stream, const char* restrict format, ...);
int fscanf(FILE* restrict stream, const char* restrict format, ...);
仅当实现定义了 __STDC_LIB_EXT1__,而且用户代码在对 <stdio.h> 的所有包含之前定义了 __STDC_WANT_LIB_EXT1__:
#if defined(__STDC_WANT_LIB_EXT1__)
#define L_tmpnam_s /* 见描述 */
#define TMP_MAX_S /* 见描述 */
typedef /* 见描述 */ errno_t;
typedef /* 见描述 */ rsize_t;
errno_t tmpfile_s(FILE* restrict* restrict streamptr);
errno_t tmpnam_s(char* s, rsize_t maxsize);
errno_t fopen_s(FILE* restrict* restrict streamptr,
const char* restrict filename, const char* restrict mode);
errno_t freopen_s(FILE* restrict* restrict newstreamptr,
const char* restrict filename, const char* restrict mode,
FILE* restrict stream);
int fprintf_s(FILE* restrict stream, const char* restrict format, ...);
int fscanf_s(FILE* restrict stream, const char* restrict format, ...);
int printf_s(const char* restrict format, ...);
int scanf_s(const char* restrict format, ...);
int snprintf_s(char* restrict s, rsize_t n, const char* restrict format, ...);
int sprintf_s(char* restrict s, rsize_t n, const char* restrict format, ...);
int sscanf_s(const char* restrict s, const char* restrict format, ...);
int vfprintf_s(FILE* restrict stream, const char* restrict format, va_list arg);
int vfscanf_s(FILE* restrict stream, const char* restrict format, va_list arg);
int vprintf_s(const char* restrict format, va_list arg);
int vscanf_s(const char* restrict format, va_list arg);
int vsnprintf_s(char* restrict s, rsize_t n, const char* restrict format, va_list arg);
int vsprintf_s(char* restrict s, rsize_t n, const char* restrict format, va_list arg);
int vsscanf_s(const char* restrict s, const char* restrict format, va_list arg);
char* gets_s(char* s, rsize_t n);
#endif