最終更新日時(UTC): 2025年07月10日 01時16分39秒
Koichi Murase が更新

履歴 編集

function
<cstdio>

std::fopen

namespace std {
  FILE* fopen(const char* filename, const char* mode);
}

概要

ファイルを開く。

modeにはファイルのモードを指定する。

戻り値

正常に実行されれば、ファイルストリームを返す。

ファイルの開き方に失敗した場合、NULLを返す。

#include <cstdio>

int main() {
  std::FILE *fp = std::fopen("test.txt", "w");
  if (fp == NULL) {
    std::printf("ファイルを開けませんでした\n");
    return 1;
  }
  std::fclose(fp);
  return 0;
}

処理系

Morty Proxy This is a proxified and sanitized view of the page, visit original site.