C++ ヘッダー ファイルの概要 -<cstdio>
ヘッダー ファイル
<cstdio>
ヘッドファイル
導入
<cstdio>
<stdio.h>
の内容をC++ヘッダファイルの形で表現するものです。<stdio.h>
これは、C 標準関数ライブラリのヘッダー ファイル、つまり標準バッファー入出力です。基本的なテキスト入力および出力ストリーム操作 (画面やファイルなどを含む) を提供します。C 言語にはテキストの入出力専用のキーワードが用意されていないため、このライブラリは最も一般的な C 言語プログラム読み込みライブラリです。
注:<cstdio>
とは<stdio.h>
同じファイルではなく、違いがあります。
概要
namespace std {
using size_t = ;
using FILE = ;
using 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 stderr
#define stdin
#define stdout
namespace std {
int remove(const char* filename);
int rename(const char* old, const char* new);
FILE* tmpfile();
char* tmpnam(char* s);
int fclose(FILE* stream);
int fflush(FILE* stream);
FILE* fopen(const char* filename, const char* mode);
FILE* freopen(const char* filename, const char* mode, FILE* stream);
void setbuf(FILE* stream, char* buf);
int setvbuf(FILE* stream, char* buf, int mode, size_t size);
int fprintf(FILE* stream, const char* format, ...);
int fscanf(FILE* stream, const char* format, ...);
int printf(const char* format, ...);
int scanf(const char* format, ...);
int snprintf(char* s, size_t n, const char* format, ...);
int sprintf(char* s, const char* format, ...);
int sscanf(const char* s, const char* format, ...);
int vfprintf(FILE* stream, const char* format, va_list arg);
int vfscanf(FILE* stream, const char* format, va_list arg);
int vprintf(const char* format, va_list arg);
int vscanf(const char* format, va_list arg);
int vsnprintf(char* s, size_t n, const char* format, va_list arg);
int vsprintf(char* s, const char* format, va_list arg);
int vsscanf(const char* s, const char* format, va_list arg);
int fgetc(FILE* stream);
char* fgets(char* s, int n, FILE* stream);
int fputc(int c, FILE* stream);
int fputs(const char* s, FILE* stream);
int getc(FILE* stream);
int getchar();
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* ptr, size_t size, size_t nmemb, FILE* stream);
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream);
int fgetpos(FILE* stream, fpos_t* 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++ ライブラリ
C 標準入出力ライブラリ ( <cstdio>
C 言語の<stdio.h>
) を使用して、入出力操作を C++ で実装することもできます。ライブラリは、いわゆる「ストリーム」を使用して、キーボード、プリンタ、端末などの物理デバイス、またはシステムでサポートされているその他の種類のファイルを操作します。ストリームは、これらの物理デバイスと均一な方法で対話するための抽象化です。すべてのストリームは、関連する物理デバイスの個々の特性に関係なく、同様の特性を持っています。
ストリームは<cstdio>
ライブラリ内で FILE オブジェクトへのポインタとして動作します。FILE オブジェクトへのポインタはストリームを一意に表し、ストリームを設計する操作のパラメータとして使用されます。
stdin、stdout、stderr という 3 つの標準ストリームがあり、これらはライブラリを使用するすべてのプログラムに対してパブリックに自動的に作成されます。
ストリームのプロパティ
ストリームには、どの関数を適用できるか、およびストリームからのデータ入出力をどのように処理するかを定義するプロパティがあります。これらのプロパティのほとんどは、関数を介してfopen
ストリームがファイルに関連付けられる (開かれる) ときに定義されます。
読み取り/書き込みアクセス
ストリームが、関連付けられた物理メディアに対して読み取りまたは書き込み (または両方) アクセスできるかどうかを指定します。
テキスト/バイナリ
テキスト ストリームは、各行が改行文字で終了する一連のテキスト行を表すものと見なされます。プログラムの動作環境によっては、一部の特殊文字をテキスト ファイル環境の特殊性に適応させるために、文字変換が行われる場合があります。一方、バイナリ ストリームは、変換を行わずに物理メディアに書き込まれる、または物理メディアから読み取られる一連の文字であり、ストリームから読み取られる、またはストリームに書き込まれる文字と 1 対 1 に対応します。
キャッシュ
キャッシュは、関連するファイルまたはデバイスに対して読み書きされる前にデータが蓄積されるメモリのブロックです。ストリームは完全にバッファリングすることも、ライン バッファリングすることも、バッファリングしないこともできます。完全にバッファリングされたストリームの場合はストリームがいっぱいになったときにデータの読み取り/書き込みが行われ、ラインバッファリングされたストリームの場合は改行文字が検出されたときにデータが読み取り/書き込みされ、バッファリングされていないストリームの場合は文字がすぐに読み取り/書き込みされます。
オリエンテーション
開くと、ストリームの方向は変わりません。これらに対して入出力操作が実行されると、適用される演算子に応じて、バイト指向またはワイドバイト指向になります (通常、 で定義された関数はバイト指向ですが、 function で定義された関数はワイドバイト指向です)。
インジケータ
ストリームは、現在の状態を示し、ストリームに対する入出力操作の動作に影響を与える特定の内部インジケーターに使用されます。
エラーインジケーター
このインジケータは、ストリームに関する操作でエラーが発生したときに設定されます。インジケーターはferror
関数によって検出でき、 、clearerr
、freopen
またはを呼び出すことでrewind
リセットできます。
ファイルの終わりインジケーター
設定されると、このストリームに対する次の読み取りまたは書き込み操作がファイルの終わりに達したことを示します。これは関数によって検出でき、feof
を呼び出すかclearerr
、freopen
再配置関数 ( rewind
、fseek
および) のいずれかを呼び出すことによってfsetpos
リセットできます。
位置インジケーター
これは、次の I/O 操作で読み取りまたは書き込みを行うための次の文字を指す、各ストリームの内部ポインターです。その値はftell
or関数で取得できfgetpos
、再配置関数 および 関数を使用して変更できrewind
ます。fseek
fsetpos
関数
アクションファイル:
-
remove
ファイルの削除(関数) -
rename
ファイルの名前を変更する(関数) -
tmpfile
一時ファイルを開く(関数) -
tmpnam
一時ファイル名を生成する (関数)
ファイルアクセス:
-
fclose
ファイルを閉じる(関数) -
fflush
フラッシュフロー(機能) -
fopen
ファイルを開く(関数) -
freopen
別のファイルまたはモード (関数) でストリームを再度開く -
setbuf
ストリームキャッシュの設定(関数) -
servbuf
ストリームバッファの変更(関数)
フォーマットされた入力/出力:
fprintf
フォーマットされたデータをストリームに書き込む (関数)
-
fscanf
フォーマットされたデータをストリームから読み取る (関数) -
printf
フォーマットされたデータをstdout
(関数)に出力します -
scanf
stdin
(関数)からフォーマットされたデータを読み取ります -
snprintf
フォーマットされたデータを固定長バッファに書き込む (関数) -
sprintf
書式設定されたデータを文字列に書き込む (関数) -
sscanf
文字列から書式設定されたデータを読み取る (関数) -
vfprintf
書式設定されたデータを可変引数リストからストリームに書き込みます (関数) -
vfscanf
フォーマットされたデータをストリームから変数引数リストに読み取ります (関数) -
vprintf
可変引数リスト内の書式設定されたデータをstdout
(関数)に出力します。 -
vscanf
フォーマットされたデータを変数引数リストに読み込みます (関数) -
vsnprintf
可変パラメータリストのフォーマット済みデータを固定長バッファに書き込みます(関数) -
vsprintf
可変引数リスト内の書式設定されたデータを文字列 (関数) に書き込みます。 -
vsscanf
書式設定されたデータを文字列から可変引数リストに読み取ります (関数)
文字列入力/出力:
-
fgetc
ストリームから文字を取得する (関数) -
fgets
ストリームから文字列を取得する(関数) -
fputc
ストリームに文字を書き込む (関数) -
fputs
文字列をストリームに書き込みます (関数) -
getc
ストリームから文字を取得する (関数) -
getchar
stdin
(関数)から文字を取得します -
gets
stdin
(関数)から文字列を取得します -
putc
ストリームに文字を書き込む (関数) -
putchar
文字を書くstdout
(関数) -
puts
stdout
(関数)に文字列を書き込みます -
ungetc
ストリーム(関数)から文字を取得しません
直接入出力:
-
fread
ストリームからデータのチャンクを読み取る (関数) -
fwrite
データのチャンクをストリームに書き込む (関数)
ファイルの場所:
-
fgetpos
ストリームから現在位置を取得する(関数) -
fseek
ストリーム位置インジケーターの再配置 (関数) -
fsetpos
ストリーム位置インジケーターの設定 (関数) -
ftell
ストリームの現在位置を取得する(関数) -
rewind
ストリーム位置を開始位置に設定 (関数)
エラー処理:
-
clearerr
エラーインジケーターのクリア(機能) -
feof
ファイルの終わりインジケーターをチェックする (関数) -
ferror
エラーインジケーターのチェック(機能) -
perror
エラーメッセージを出力する(関数)
大きい
-
BUFSIZE
バッファサイズ(定数) -
EOF
ファイルの終わり (定数) -
FILENAME_MAX
ファイル名の最大長(定数) -
FOPEN_MAX
継続的に開いているストリームの潜在的な制限 (一定) -
L_tmpnam
一時ファイル名の最小長 (定数) -
NULLnull
ポインタ(マクロ) -
TMP_MAX
一時ファイルの数(定数) -
また:
_IOFBF
、_IOLBF
、_IONBF
( で使用setvbuf
) -
SEEK_CUR
、SEEK_END
およびSEEK_SET
( で使用されますfseek
)。
タイプ
-
FILE
制御フローに関する情報を含むオブジェクト (タイプ) -
fpos_t
ファイル内の指定された場所にある情報を含むオブジェクト (タイプ) -
size_t
符号なし整数型 (type)
コンテンツ
// -*- C++ -*- forwarding
header.
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// ISO C++ 14882: 27.8.2 C Library files
//
/** @file cstdio
* This is a Standard C++ Library file. You should @c #include this file
* in your programs, rather than any of the "*.h" implementation files.
*
* This is the C++ version of the Standard C Library header @cstdio.h,
* and its contents are (mostly) the same as that header, but are all
* contained in the namespace @cstd.
*/
#ifndef _GLIBCXX_CSTDIO
#define _GLIBCXX_CSTDIO 1
#pragma GCC system_header
#include <bits/c++config.h>
#include <cstddef>
#include <stdio.h>
// Get rid of those macros defined in <stdio.h> in lieu of real functions.
#undef clearerr
#undef fclose
#undef feof
#undef ferror
#undef fflush
#undef fgetc
#undef fgetpos
#undef fgets
#undef fopen
#undef fprintf
#undef fputc
#undef fputs
#undef fread
#undef freopen
#undef fscanf
#undef fseek
#undef fsetpos
#undef ftell
#undef fwrite
#undef getc
#undef getchar
#undef gets
#undef perror
#undef printf
#undef putc
#undef putchar
#undef puts
#undef remove
#undef rename
#undef rewind
#undef scanf
#undef setbuf
#undef setvbuf
#undef sprintf
#undef sscanf
#undef tmpfile
#undef tmpnam
#undef ungetc
#undef vfprintf
#undef vprintf
#undef vsprintf
namespace std
{
using ::FILE;
using ::fpos_t;
using ::clearerr;
using ::fclose;
using ::feof;
using ::ferror;
using ::fflush;
using ::fgetc;
using ::fgetpos;
using ::fgets;
using ::fopen;
using ::fprintf;
using ::fputc;
using ::fputs;
using ::fread;
using ::freopen;
using ::fscanf;
using ::fseek;
using ::fsetpos;
using ::ftell;
using ::fwrite;
using ::getc;
using ::getchar;
using ::gets;
using ::perror;
using ::printf;
using ::putc;
using ::putchar;
using ::puts;
using ::remove;
using ::rename;
using ::rewind;
using ::scanf;
using ::setbuf;
using ::setvbuf;
using ::sprintf;
using ::sscanf;
using ::tmpfile;
using ::tmpnam;
using ::ungetc;
using ::vfprintf;
using ::vprintf;
using ::vsprintf;
}
#if _GLIBCXX_USE_C99
#undef snprintf
#undef vfscanf
#undef vscanf
#undef vsnprintf
#undef vsscanf
namespace __gnu_cxx
{
#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
extern "C" int
(snprintf)(char *
restrict,
size_t,
const char * restrict, ...);
extern "C" int
(
vfscanf)(FILE * restrict, const char * restrict, __gnuc_va_list);
extern "C" int (
vscanf)(const char *
restrict, __gnuc_va_list);
extern "C" int
(vsnprintf)(char * restrict,
size_t,
const char * restrict, __gnuc_va_list);
extern "C" int
(
vsscanf)(const char * restrict, const char * restrict, __gnuc_va_list);
#endif
#if !_GLIBCXX_USE_C99_DYNAMIC
using ::snprintf;
using ::
vfscanf;
using ::
vscanf;
using ::vsnprintf;
using ::vsscanf;
#endif
}
namespace std
{
using __gnu_cxx::
snprintf;
using __gnu_cxx::vfscanf;
using __gnu_cxx::vscanf;
using __gnu_cxx::vsnprintf;
using __gnu_cxx::
vsscanf;
}
#endif