std:: feof
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<cstdio>
|
||
|
int
feof
(
std::
FILE
*
stream
)
;
|
||
指定されたファイルストリームの終端に達したかどうかをチェックします。
目次 |
パラメータ
| stream | - | チェックするファイルストリーム |
戻り値
ストリームの終端に達した場合はゼロ以外の値、それ以外の場合は 0 。
注記
この関数は直近のI/O操作で報告されたストリーム状態のみを報告し、関連するデータソースを検査しません。例えば、直近のI/Oが
std::fgetc
であり、ファイルの最終バイトを返した場合、
std::feof
はゼロを返します。次の
std::fgetc
は失敗し、ストリーム状態を
end-of-file
に変更します。その時のみ
std::feof
は非ゼロを返します。
一般的な使用法では、入力ストリームの処理はエラーが発生すると停止します。
その後、
feof
および
std::ferror
を使用して、異なるエラー状態を区別します。
例
#include <cstdio> #include <cstdlib> int main() { int is_ok = EXIT_FAILURE; FILE* fp = std::fopen("/tmp/test.txt", "w+"); if (!fp) { std::perror("File opening failed"); return is_ok; } int c; // Note: int, not char, required to handle EOF while ((c = std::fgetc(fp)) != EOF) // Standard C I/O file reading loop std::putchar(c); if (std::ferror(fp)) std::puts("I/O error when reading"); else if (std::feof(fp)) { std::puts("End of file reached successfully"); is_ok = EXIT_SUCCESS; } std::fclose(fp); return is_ok; }
出力:
End of file reached successfully
関連項目
|
ファイル終端に達したかどうかをチェックする
(
std::basic_ios<CharT,Traits>
の公開メンバ関数)
|
|
|
エラーをクリアする
(関数) |
|
|
現在のエラーに対応する文字列を
stderr
に表示する
(関数) |
|
|
ファイルエラーをチェックする
(関数) |
|
|
Cドキュメント
for
feof
|
|