#include <stdio.h> extern~FILE~~*stdin; extern~FILE~~*stdout; extern~FILE~~*stderr;
A stream is associated with an external file (which may be a physical device) by opening a file, which may involve creating a new file. Creating an existing file causes its former contents to be discarded. If a file can support positioning requests (such as a disk file, as opposed to a terminal), then a file position indicator associated with the stream is positioned at the start of the file (byte zero), unless the file is opened with append mode. If append mode is used, it is unspecified whether the position indicator will be placed at the start or the end of the file. The position indicator is maintained by subsequent reads, writes, and positioning requests. All input occurs as if the characters were read by successive calls to the fgetc(3) function; all output takes place as if all characters were written by successive calls to the fputc(3) function.
A file is disassociated from a stream by closing the file. Output streams are flushed (any unwritten buffer contents are transferred to the host environment) before the stream is disassociated from the file. The value of a pointer to a FILE object is indeterminate after a file is closed (garbage).
A file may be subsequently reopened, by the same or another program execution, and its contents reclaimed or modified (if it can be repositioned at the start). If the main function returns to its original caller, or the exit(3) function is called, all open files are closed (hence all output streams are flushed) before program termination. Other methods of program termination, such as abort(3) do not bother about closing files properly.
プログラムの起動時に 3 個のテキストストリームが予め定義されており、 それらは明示的に開く必要がない。 標準入力 (standard input) (通常の入力を読み取るのに使う)、 標準出力 (standard output) (通常の出力を書き込むのに使う)、 標準エラー出力 (standard error) (診断出力を書き込むのに使う) である。 これらのストリームは stdin, stdout, stderr と短縮して表現される。 オープンされたときには、 標準エラーストリームは 完全にはバッファーリングされていない。 標準入力ストリームと標準出力ストリームは、 ストリームがインタラクティブなデバイスを参照していなければ、 完全にバッファーリングされている。
端末デバイスを参照する出力ストリームは、 デフォルトでは常に行単位でバッファーリングされている。 ただしそのようなストリームにおけるバッファー内の出力は、 端末デバイスを参照している入力ストリームからの読み込みがあるたびに、 自動的に書き込まれる。 出力端末に行の一部を書き込んだ後で大量の計算を行う場合、 出力が表示されるように、計算に取りかかる前に標準出力に対して fflush(3) を実行する必要がある。
The stdio library is a part of the library libc and routines are automatically loaded as needed by cc(1). The SYNOPSIS sections of the following manual pages indicate which include files are to be used, what the compiler declaration for the function looks like, and which external variables are of interest.
BUFSIZ, EOF, FILENAME_MAX, FOPEN_MAX, L_cuserid, L_ctermid, L_tmpnam, NULL, SEEK_END, SEEK_SET, SEEK_CUR, TMP_MAX, clearerr, feof, ferror, fileno, getc, getchar, putc, putchar, stderr, stdin, stdout はマクロとして定義されている。 これらの名前は、現在の定義を #undef で削除しない限り、再利用することはできない。 マクロ関数の関数版として、 feof, ferror, clearerr, fileno, getc, getchar, putc, putchar がある。 マクロの定義が明示的に消去されている場合には、 これらを使用することになるだろう。
| 関数 | 説明 |
|
clearerr(3) |
ストリームの状態の確認とリセット
|
|
fclose(3) |
ストリームをクローズする
|
|
fdopen(3) |
ストリームをオープンする
|
|
feof(3) |
ストリームの状態の確認とリセット
|
|
ferror(3) |
ストリームの状態の確認とリセット
|
|
fflush(3) |
ストリームをフラッシュする
|
|
fgetc(3) |
次の文字または語を入力ストリームから取得する
|
|
fgetpos(3) |
ストリームの位置指示子を移動する
|
|
fgets(3) |
行を入力ストリームから取得する
|
|
fileno(3) |
引数であるストリームの整数値のディスクリプターを返す
|
| fmemopen(3) |
open memory as stream
|
|
fopen(3) |
ストリームをオープンする
|
| fopencookie(3) |
open a custom stream
|
|
fprintf(3) |
書式付き出力変換
|
|
fpurge(3) |
ストリームをフラッシュする
|
|
fputc(3) |
文字または語をストリームに出力する
|
|
fputs(3) |
行をストリームに出力する
|
|
fread(3) |
バイナリーストリーム入出力
|
|
freopen(3) |
ストリームをオープンする
|
|
fscanf(3) |
書式付き入力変換
|
| fseek(3) |
ストリームの位置指示子を移動する
|
|
fsetpos(3) |
ストリームの位置指示子を移動する
|
|
ftell(3) |
ストリームの位置指示子を移動する
|
|
fwrite(3) |
バイナリーストリーム入出力
|
|
getc(3) |
次の文字または語を入力ストリームから取得する
|
|
getchar(3) |
次の文字または語を入力ストリームから取得する
|
|
gets(3) |
行を入力ストリームから取得する
|
|
getw(3) |
次の文字または語を入力ストリームから取得する
|
|
mktemp(3) |
他と重ならないテンポラリファイル名を作る
|
| open_memstream(3) |
open a dynamic memory buffer stream
|
| open_wmemstream(3) |
open a dynamic memory buffer stream
|
|
perror(3) |
システムエラーメッセージ
|
| printf(3) |
書式付き出力変換
|
|
putc(3) |
文字または語をストリームに出力する
|
|
putchar(3) |
文字または語をストリームに出力する
|
|
puts(3) |
行をストリームに出力する
|
|
putw(3) |
文字または語をストリームに出力する
|
|
remove(3) |
ディレクトリエントリーを削除する
|
|
rewind(3) |
ストリームの位置指示子を移動する
|
|
scanf(3) |
書式付き入力変換
|
|
setbuf(3) |
ストリームのバッファーリングの操作
|
|
setbuffer(3) |
ストリームのバッファーリングの操作
|
|
setlinebuf(3) |
ストリームのバッファーリングの操作
|
|
setvbuf(3) |
ストリームのバッファーリングの操作
|
|
sprintf(3) |
書式付き出力変換
|
|
sscanf(3) |
書式付き入力変換
|
|
strerror(3) |
システムエラーメッセージ
|
|
sys_errlist(3) |
システムエラーメッセージ
|
|
sys_nerr(3) |
システムエラーメッセージ
|
|
tempnam(3) |
テンポラリファイルの操作
|
|
tmpfile(3) |
テンポラリファイルの操作
|
|
tmpnam(3) |
テンポラリファイルの操作
|
|
ungetc(3) |
入力ストリームへ 1 文字戻す
|
|
vfprintf(3) |
書式付き出力変換
|
|
vfscanf(3) |
書式付き入力変換
|
|
vprintf(3) |
書式付き出力変換
|
|
vscanf(3) |
書式付き入力変換
|
|
vsprintf(3) |
書式付き出力変換
|
|
vsscanf(3) |
書式付き入力変換
|