名前空間
変種
操作

「cpp/io/c/feof」の版間の差分

提供: cppreference.com
< cpp‎ | io‎ | c
(1版:Translate from the English version)
 
(1人の利用者による、間の3版が非表示)
1行: 1行:
{{tr_note}}
 
 
{{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 );
 
}}
 
}}
  
{{tr|与えられたファイルストリームの終わりかどうかをチェックするに達しています.|Checks if the end of the given file stream has been reached.}}
+
  
===パラメータ===
+
======
{{param list begin}}
+
{{begin}}
{{param list item | stream |{{tr| ファイルストリームをチェックする | the file stream to check }}}}
+
{{| stream | }}
{{param list end}}
+
{{end}}
  
===値を返します===
+
======
{{tr|ストリームの終わりに達した場合はゼロ以外の値、そうでなければ{{c|0}}.|Nonzero value if the end of the stream has been reached, otherwise {{c|0}}.}}
+
{{c|0}}
  
 
===ノート===
 
===ノート===
{{tr|最新のI / O操作によって報告されるように、この関数は、ストリームの状態を報告し、それが関連付けられているデータソースを調べません。最新のI / Oは、ファイルの最後のバイトを戻さ{{c|std::fgetc}}だった場合、例えば、{{tt|std::feof}}は、ゼロ以外の値を返します。次の{{c|std::fgetc}}は失敗し、''エンド·オブ·ファイル''をストリームの状態を変更します。だけにして{{tt|std::feof}}ゼロを返し.|This function only reports the stream state as reported by the most recent I/O operation, it does not examine the associated data source. For example, if the most recent I/O was a {{c|std::fgetc}}, which returned the last byte of a file, {{tt|std::feof}} returns non-zero. The next {{c|std::fgetc}} fails and changes the stream state to ''end-of-file''. Only then {{tt|std::feof}} returns zero.}}
+
{{|std::fgetc}} {{tt|std::feof}} {{|std::fgetc}} ''''{{tt|std::feof}}
  
{{tr|典型的な使い方では、入力ストリームの処理が何らかのエラーで停止します。{{tt|feof}}{{c|std::ferrror}}その後、さまざまなエラー条件を区別するために使用され.|In typical usage, input stream processing stops on any error; {{tt|feof}} and {{c|std::ferrror}} are then used to distinguish between different error conditions.}}
+
{{tt|feof}} {{|std::}}
  
 
===例===
 
===例===
 
{{example template|cpp/io/c/example1}}
 
{{example template|cpp/io/c/example1}}
  
===も参照してください===
+
======
{{dcl list begin}}
+
{{begin}}
{{dcl list template | cpp/io/basic_ios/dcl list eof}}
+
{{| cpp/io/basic_ios/eof}}
{{dcl list template | cpp/io/c/dcl list clearerr}}
+
{{| cpp/io/c/clearerr}}
{{dcl list template | cpp/io/c/dcl list perror}}
+
{{| cpp/io/c/perror}}
{{dcl list template | cpp/io/c/dcl list ferror}}
+
{{| cpp/io/c/ferror}}
{{dcl list see c | c/io/feof}}
+
{{see c | c/io/feof}}
{{dcl list end}}
+
{{end}}
  
 
[[cs:cpp/io/c/feof]]
 
[[cs:cpp/io/c/feof]]
 +
 +
 +
 
[[fr:cpp/io/c/feof]]
 
[[fr:cpp/io/c/feof]]
[[ja:cpp/io/c/feof]]
+
[[
 +
 +
:cpp/io/c/feof]]
 
[[zh:cpp/io/c/feof]]
 
[[zh:cpp/io/c/feof]]

2018年5月3日 (木) 21:29時点における最新版

 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
C スタイルの入出力
型とオブジェクト
関数
ファイルアクセス
直接入出力
書式なし入出力
書式付き入力
書式付き出力
ファイル位置操作
エラー処理
feof
ファイルに対する操作
 
ヘッダ <cstdio> で定義
int feof( std::FILE* stream );

指定されたファイルストリームの終端に達したかどうか調べます。

目次

[編集] 引数

stream - 調べるファイルストリーム

[編集] 戻り値

ストリームの終端に達した場合は非ゼロの値、そうでなければ 0

[編集] ノート

この関数は最も最近の入出力操作によって報告されたストリームの状態を報告するだけです。 紐付けられているデータソースは調べられません。 例えば、最も最近の入出力が std::fgetc であって、それがファイルの最後のバイトを返した場合、 std::feof はゼロを返します。 次の std::fgetc は失敗し、ストリームの状態をファイル終端に変更します。 その後にのみ、 std::feof は非ゼロを返します。

一般的な使用方法では、何らかのエラーが発生した場合に入力ストリームの処理を停止します。 feof および std::ferror は、そのとき、異なるエラー状況を区別するために使用することができます。

[編集]

#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>のパブリックメンバ関数) [edit]
エラーをクリアします
(関数) [edit]
現在のエラーに対応する文字列を stderr に出力します
(関数) [edit]
ファイルのエラーを調べます
(関数) [edit]