最終更新日時:
が更新

履歴 編集

function
<cstdio>

std::clearerr

namespace std {
  void clearerr(FILE* stream);
}

概要

ファイルストリームのエラー状態とファイル終端の状態をクリアする。

これによって、ferror()feof()0を返すようになる。

戻り値

なし。

#include <cstdio>

int main()
{
  std::FILE* fp = std::fopen("test.txt", "w+");
  std::fputs("A", fp);
  std::rewind(fp);

  // 終端まで読み込む
  while (std::fgetc(fp) != EOF) {}
  std::printf("%d\n", std::feof(fp) != 0);

  // 終端の状態をクリアする
  std::clearerr(fp);
  std::printf("%d\n", std::feof(fp) != 0);

  std::fclose(fp);
}

出力

1
0

関連項目