stdio.h

stdio.h

一般地,在C語言或C++中,會把用來#include的文件的擴展名叫 .h,稱其為頭文件。 #include文件的目的就是把多個編譯單元(也就是c或者cpp文件)公用的內容,單獨放在一個文件里減少整體代碼尺寸;或者提供跨工程公共代碼。在現行的c++版本中,應用這個頭文件應是#include

簡介


stdio.h
stdio.h
stdio 就是指“standard input & output"(標準輸入輸出)
所以,源代碼中如用到標準輸入輸出函數時,就要包含這個頭文件!
例如c語言中的 printf("%d",i); scanf("%d",&i);等函數。

引用方法


#include
(註:在TC2.0中,允許不引用此頭文件而直接調用其中的函數,但這種做法是不標準的。也不建議這樣做。以避免出現在其他IDE中無法編譯或執行的問題。)

標準函數


1
2
3
4
5
6
7
int getchar()//從標準輸入設備寫入一個字元
int putchar()//向標準輸出設備讀出一個字元
int scanf(char*format[,argument…])//從標準輸入設備讀入格式化后的數據
int printf(char*format[,argument…])//向標準輸出設備輸出格式化字元串
char* gets(char*string)//從標準輸入設備讀入一個字元串
int puts(char*string)//向標準輸出設備輸出一個字元串
int sprintf(char*string,char*format[,…])//把格式化的數據寫入某個字元串緩衝區

文件內容


文件說明

1
2
3
4
5
6
7
8
9
10
11
12

宏定義

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef_STDIO_H_
#define_STDIO_H_
#include<_mingw.h>
#ifndefRC_INVOKED
#define__need_size_t
#define__need_NULL
#define__need_wchar_t
#define__need_wint_t
#include
#define__need___va_list
#include
#endif
#define_IOREAD1
#define_IOWRT2
#define_IORW0x0080
#defineSTDIN_FILENO0
#defineSTDOUT_FILENO1
#defineSTDERR_FILENO2
#defineEOF(-1)
#ifndefFILENAME_MAX
#defineFILENAME_MAX(260)
#endif
#defineFOPEN_MAX(20)
#defineTMP_MAX32767
#define_P_tmpdir"\\"
#ifndef__STRICT_ANSI__
#defineP_tmpdir_P_tmpdir
#endif
#define_wP_tmpdirL"\\"
#defineL_tmpnam(16)
#define_IOFBF0x0000
#define_IOLBF0x0040
#define_IONBF0x0004
#define_IOMYBUF0x0008
#define_IOEOF0x0010
#define_IOERR0x0020
#define_IOSTRG0x0040
#ifdef_POSIX_SOURCE
#define_IOAPPEND0x0200
#endif
#defineBUFSIZ512
#ifndefSEEK_SET
#defineSEEK_SET(0)
#endif
#ifndefSEEK_CUR
#defineSEEK_CUR(1)
#endif
#ifndefSEEK_END
#defineSEEK_END(2)
#endif
#ifndefRC_INVOKED
#ifndef__VALIST
#ifdef__GNUC__
#define__VALIST__gnuc_va_list
#else
#define__VALISTchar*
#endif
#endif
#ifndef_FILE_DEFINED
#define_FILE_DEFINED

結構體定義

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
typedefstruct_iobuf
{
char*_ptr;
int_cnt;
char*_base;
int_flag;
int_file;
int_charbuf;
int_bufsiz;
char*_tmpfname;
}FILE;
#endif
#ifndef__DECLSPEC_SUPPORTED
externFILE(*_imp___iob)[];
#define_iob(*_imp___iob)
#else
__MINGW_IMPORTFILE_iob[];
#endif
#definestdin(&_iob[STDIN_FILENO])
#definestdout(&_iob[STDOUT_FILENO])
#definestderr(&_iob[STDERR_FILENO])

操作函數定義

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#ifdef__cplusplus
extern"C"{
#endif
_CRTIMPFILE*__cdeclfopen(constchar*,constchar*);
_CRTIMPFILE*__cdeclfreopen(constchar*,constchar*,FILE*);
_CRTIMPint__cdeclfflush(FILE*);
_CRTIMPint__cdeclfclose(FILE*);
_CRTIMPint__cdeclremove(constchar*);
_CRTIMPint__cdeclrename(constchar*,constchar*);
_CRTIMPFILE*__cdecltmpfile(void);
_CRTIMPchar*__cdecltmpnam(char*);
#ifndef__STRICT_ANSI__
_CRTIMPchar*__cdecl_tempnam(constchar*,constchar*);
_CRTIMPint__cdecl_rmtmp(void);
#ifndefNO_OLDNAMES
_CRTIMPchar*__cdecltempnam(constchar*,constchar*);
_CRTIMPint__cdeclrmtmp(void);
#endif
#endif
_CRTIMPint__cdeclsetvbuf(FILE*,char*,int,size_t);
_CRTIMPvoid__cdeclsetbuf(FILE*,char*);
_CRTIMPint__cdeclfprintf(FILE*,constchar*,...);
_CRTIMPint__cdeclprintf(constchar*,...);
_CRTIMPint__cdeclsprintf(char*,constchar*,...);
_CRTIMPint__cdecl_snprintf(char*,size_t,constchar*,...);
_CRTIMPint__cdeclvfprintf(FILE*,constchar*,__VALIST);
_CRTIMPint__cdeclvprintf(constchar*,__VALIST);
_CRTIMPint__cdeclvsprintf(char*,constchar*,__VALIST);
_CRTIMPint__cdecl_vsnprintf(char*,size_t,constchar*,__VALIST);
#ifndef__NO_ISOCEXT
int__cdeclsnprintf(char*s,size_tn,constchar*format,...);
__CRT_INLINEint__cdecl
vsnprintf(char*s,size_tn,constchar*format,__VALISTarg)
{return_vsnprintf(s,n,format,arg);}
int__cdeclvscanf(constchar*__restrict__,__VALIST);
int__cdeclvfscanf(FILE*__restrict__,constchar*__restrict__,
__VALIST);
int__cdeclvsscanf(constchar*__restrict__,
constchar*__restrict__,__VALIST);
#endif
_CRTIMPint__cdeclfscanf(FILE*,constchar*,...);
_CRTIMPint__cdeclscanf(constchar*,...);
_CRTIMPint__cdeclsscanf(constchar*,constchar*,...);
_CRTIMPint__cdeclfgetc(FILE*);
_CRTIMPchar*__cdeclfgets(char*,int,FILE*);
_CRTIMPint__cdeclfputc(int,FILE*);
_CRTIMPint__cdeclfputs(constchar*,FILE*);
_CRTIMPchar*__cdeclgets(char*);
_CRTIMPint__cdeclputs(constchar*);
_CRTIMPint__cdeclungetc(int,FILE*);
_CRTIMPint__cdecl_filbuf(FILE*);
_CRTIMPint__cdecl_flsbuf(int,FILE*);
#if!defined_MT
__CRT_INLINEint__cdeclgetc(FILE*__F)
{
return(--__F->_cnt>=0)
?(int)(unsignedchar)*__F->_ptr++
:_filbuf(__F);
}
__CRT_INLINEint__cdeclputc(int__c,FILE*__F)
{
return(--__F->_cnt>=0)
?(int)(unsignedchar)(*__F->_ptr++=(char)__c)
:_flsbuf(__c,__F);
}
__CRT_INLINEint__cdeclgetchar(void)
{
return(--stdin->_cnt>=0)
?(int)(unsignedchar)*stdin->_ptr++
:_filbuf(stdin);
}
__CRT_INLINEint__cdeclputchar(int__c)
{
return(--stdout->_cnt>=0)
?(int)(unsignedchar)(*stdout->_ptr++=(char)__c)
:_flsbuf(__c,stdout);}
#else
_CRTIMPint__cdeclgetc(FILE*);
_CRTIMPint__cdeclputc(int,FILE*);
_CRTIMPint__cdeclgetchar(void);
_CRTIMPint__cdeclputchar(int);
#endif
_CRTIMPsize_t__cdeclfread(void*,size_t,size_t,FILE*);
_CRTIMPsize_t__cdeclfwrite(constvoid*,size_t,size_t,FILE*);
_CRTIMPint__cdeclfseek(FILE*,long,int);
_CRTIMPlong__cdeclftell(FILE*);
_CRTIMPvoid__cdeclrewind(FILE*);
#ifdef__USE_MINGW_FSEEK
int__cdecl__mingw_fseek(FILE*,long,int);
int__cdecl__mingw_fwrite(constvoid*,size_t,size_t,FILE*);
#definefseek(fp,offset,whence)__mingw_fseek(fp,offset,whence)
#definefwrite(buffer,size,count,fp)__mingw_fwrite(buffer,size,count,fp)
#endif
#ifdef__MSVCRT__
typedeflonglongfpos_t;
#else
typedeflongfpos_t;
#endif
_CRTIMPint__cdeclfgetpos(FILE*,fpos_t*);
_CRTIMPint__cdeclfsetpos(FILE*,constfpos_t*);
_CRTIMPint__cdeclfeof(FILE*);
_CRTIMPint__cdeclferror(FILE*);
#ifdef__cplusplus
inlineint__cdeclfeof(FILE*__F)
{return__F->_flag&_IOEOF;}
inlineint__cdeclferror(FILE*__F)
{return__F->_flag&_IOERR;}
#else
#definefeof(__F)((__F)->_flag&_IOEOF)
#defineferror(__F)((__F)->_flag&_IOERR)
#endif
_CRTIMPvoid__cdeclclearerr(FILE*);
_CRTIMPvoid__cdeclperror(constchar*);
#ifndef__STRICT_ANSI__
_CRTIMPFILE*__cdecl_popen(constchar*,constchar*);
_CRTIMPint__cdecl_pclose(FILE*);
#ifndefNO_OLDNAMES
_CRTIMPFILE*__cdeclpopen(constchar*,constchar*);
_CRTIMPint__cdeclpclose(FILE*);
#endif
_CRTIMPint__cdecl_flushall(void);
_CRTIMPint__cdecl_fgetchar(void);
_CRTIMPint__cdecl_fputchar(int);
_CRTIMPFILE*__cdecl_fdopen(int,constchar*);
_CRTIMPint__cdecl_fileno(FILE*);
_CRTIMPint__cdecl_fcloseall(void);
_CRTIMPFILE*__cdecl_fsopen(constchar*,constchar*,int);
#ifdef__MSVCRT__
_CRTIMPint__cdecl_getmaxstdio(void);
_CRTIMPint__cdecl_setmaxstdio(int);
#endif
#ifndef_NO_OLDNAMES
_CRTIMPint__cdeclfgetchar(void);
_CRTIMPint__cdeclfputchar(int);
_CRTIMPFILE*__cdeclfdopen(int,constchar*);
_CRTIMPint__cdeclfileno(FILE*);
#endif
#define_fileno(__F)((__F)->_file)
#ifndef_NO_OLDNAMES
#definefileno(__F)((__F)->_file)
#endif
#ifdefined(__MSVCRT__)&&!defined(__NO_MINGW_LFS)
#include
__CRT_INLINEFILE*__cdeclfopen64(constchar*filename,constchar*mode)
{
returnfopen(filename,mode);
}
int__cdeclfseeko64(FILE*,off64_t,int);
#ifdef__USE_MINGW_FSEEK
int__cdecl__mingw_fseeko64(FILE*,off64_t,int);
#definefseeko64(fp,offset,whence)__mingw_fseeko64(fp,offset,whence)
#endif
__CRT_INLINEoff64_t__cdeclftello64(FILE*stream)
{
fpos_tpos;
if(fgetpos(stream,&pos))
return-1LL;
else
return((off64_t)pos);
}
#endif
#endif
#ifndef_WSTDIO_DEFINED
_CRTIMPint__cdeclfwprintf(FILE*,constwchar_t*,...);
_CRTIMPint__cdeclwprintf(constwchar_t*,...);
_CRTIMPint__cdeclswprintf(wchar_t*,constwchar_t*,...);
_CRTIMPint__cdecl_snwprintf(wchar_t*,size_t,constwchar_t*,...);
_CRTIMPint__cdeclvfwprintf(FILE*,constwchar_t*,__VALIST);
_CRTIMPint__cdeclvwprintf(constwchar_t*,__VALIST);
_CRTIMPint__cdeclvswprintf(wchar_t*,constwchar_t*,__VALIST);
_CRTIMPint__cdecl_vsnwprintf(wchar_t*,size_t,constwchar_t*,__VALIST);
_CRTIMPint__cdeclfwscanf(FILE*,constwchar_t*,...);
_CRTIMPint__cdeclwscanf(constwchar_t*,...);
_CRTIMPint__cdeclswscanf(constwchar_t*,constwchar_t*,...);
_CRTIMPwint_t__cdeclfgetwc(FILE*);
_CRTIMPwint_t__cdeclfputwc(wchar_t,FILE*);
_CRTIMPwint_t__cdeclungetwc(wchar_t,FILE*);
#ifdef__MSVCRT__
_CRTIMPwchar_t*__cdeclfgetws(wchar_t*,int,FILE*);
_CRTIMPint__cdeclfputws(constwchar_t*,FILE*);
_CRTIMPwint_t__cdeclgetwc(FILE*);
_CRTIMPwint_t__cdeclgetwchar(void);
_CRTIMPwchar_t*__cdecl_getws(wchar_t*);
_CRTIMPwint_t__cdeclputwc(wint_t,FILE*);
_CRTIMPint__cdecl_putws(constwchar_t*);
_CRTIMPwint_t__cdeclputwchar(wint_t);
_CRTIMPFILE*__cdecl_wfdopen(int,wchar_t*);
_CRTIMPFILE*__cdecl_wfopen(constwchar_t*,constwchar_t*);
_CRTIMPFILE*__cdecl_wfreopen(constwchar_t*,constwchar_t*,FILE*);
_CRTIMPFILE*__cdecl_wfsopen(constwchar_t*,constwchar_t*,int);
_CRTIMPwchar_t*__cdecl_wtmpnam(wchar_t*);
_CRTIMPwchar_t*__cdecl_wtempnam(constwchar_t*,constwchar_t*);
_CRTIMPint__cdecl_wrename(constwchar_t*,constwchar_t*);
_CRTIMPint__cdecl_wremove(constwchar_t*);
_CRTIMPvoid__cdecl_wperror(constwchar_t*);
_CRTIMPFILE*__cdecl_wpopen(constwchar_t*,constwchar_t*);
#endif
#ifndef__NO_ISOCEXT
int__cdeclsnwprintf(wchar_t*s,size_tn,constwchar_t*format,...);
__CRT_INLINEint__cdecl
vsnwprintf(wchar_t*s,size_tn,constwchar_t*format,__VALISTarg)
{return_vsnwprintf(s,n,format,arg);}
int__cdeclvwscanf(constwchar_t*__restrict__,__VALIST);
int__cdeclvfwscanf(FILE*__restrict__,
constwchar_t*__restrict__,__VALIST);
int__cdeclvswscanf(constwchar_t*__restrict__,
constwchar_t*__restrict__,__VALIST);
#endif
#define_WSTDIO_DEFINED
#endif
#ifndef__STRICT_ANSI__
#ifdef__MSVCRT__
#ifndefNO_OLDNAMES
_CRTIMPFILE*__cdeclwpopen(constwchar_t*,constwchar_t*);
#endif
#endif
_CRTIMPwint_t__cdecl_fgetwchar(void);
_CRTIMPwint_t__cdecl_fputwchar(wint_t);
_CRTIMPint__cdecl_getw(FILE*);
_CRTIMPint__cdecl_putw(int,FILE*);
#ifndef_NO_OLDNAMES
_CRTIMPwint_t__cdeclfgetwchar(void);
_CRTIMPwint_t__cdeclfputwchar(wint_t);
_CRTIMPint__cdeclgetw(FILE*);
_CRTIMPint__cdeclputw(int,FILE*);
#endif
#endif
#ifdef__cplusplus
}
#endif
#endif
#endif
 
stdio.h所包含的函數:
 
文件訪問
fopen
freopen
fflush
fclose
二進位輸入/輸出
fread
fwrite
非格式化輸入/輸出
fgetc/getc
fputc/putc
ungetc
fgets
fputs
格式化輸入/輸出
scanf/fscanf/sscanf
printf/fprintf/sprintf
perror
文件定位
ftell
fseek
fgetpos
fsetpos
rewind
錯誤處理
feof
ferror
文件操作
remove
rename
tmpfile