「cpp/io/c/feof」の版間の差分
提供: cppreference.com
細 (Fix some translations) |
|||
1行: | 1行: | ||
− | |||
{{cpp/title | feof}} | {{cpp/title | feof}} | ||
{{cpp/io/c/navbar}} | {{cpp/io/c/navbar}} | ||
{{ddcl | header=cstdio | | {{ddcl | header=cstdio | | ||
− | int feof( FILE* stream ); | + | int feof( FILE* stream ); |
}} | }} | ||
− | + | ||
− | === | + | ====== |
{{par begin}} | {{par begin}} | ||
− | {{par | stream | | + | {{par | stream | }} |
{{par end}} | {{par end}} | ||
− | === | + | ====== |
− | + | {{c|0}} | |
===ノート=== | ===ノート=== | ||
− | + | {{lc|std::fgetc}} {{tt|std::feof}} {{lc|std::fgetc}} ''''{{tt|std::feof}} | |
− | + | {{tt|feof}} {{|std::}} | |
===例=== | ===例=== | ||
{{example template|cpp/io/c/example1}} | {{example template|cpp/io/c/example1}} | ||
− | === | + | ====== |
{{dsc begin}} | {{dsc begin}} | ||
{{dsc inc | cpp/io/basic_ios/dsc eof}} | {{dsc inc | cpp/io/basic_ios/dsc eof}} |
2018年5月3日 (木) 21:29時点における最新版
ヘッダ <cstdio> で定義
|
||
int feof( std::FILE* stream ); |
||
指定されたファイルストリームの終端に達したかどうか調べます。
目次 |
[編集] 引数
stream | - | 調べるファイルストリーム |
[編集] 戻り値
ストリームの終端に達した場合は非ゼロの値、そうでなければ 0。
[編集] ノート
この関数は最も最近の入出力操作によって報告されたストリームの状態を報告するだけです。 紐付けられているデータソースは調べられません。 例えば、最も最近の入出力が std::fgetc であって、それがファイルの最後のバイトを返した場合、 std::feof
はゼロを返します。 次の std::fgetc は失敗し、ストリームの状態をファイル終端に変更します。 その後にのみ、 std::feof
は非ゼロを返します。
一般的な使用方法では、何らかのエラーが発生した場合に入力ストリームの処理を停止します。 feof
および std::ferror は、そのとき、異なるエラー状況を区別するために使用することができます。
[編集] 例
Run this code
#include <stdio.h> #include <stdlib.h> int main(void) { FILE* fp = fopen("test.txt", "r"); if(!fp) { perror("File opening failed"); return EXIT_FAILURE; } int c; // note: int, not char, required to handle EOF while ((c = fgetc(fp)) != EOF) { // standard C I/O file reading loop putchar(c); } if (ferror(fp)) puts("I/O error when reading"); else if (feof(fp)) puts("End of file reached successfully"); fclose(fp); }
[編集] 関連項目
ファイル終端に達したかどうか調べます ( std::basic_ios<CharT,Traits> のパブリックメンバ関数)
| |
エラーをクリアします (関数) | |
現在のエラーに対応する文字列を stderr に出力します (関数) | |
ファイルのエラーを調べます (関数) | |
feof の C言語リファレンス
|