GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::setbuf - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. cstdio
  3. setbuf

最終更新日時: 2026年09月08日 16時16分41秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<cstdio>

std::setbuf

namespace std {
  void setbuf(FILE* stream, char* buf);
}

概要

ファイルストリームが使用する入出力バッファを設定する。

bufがヌルポインタでない場合はsetvbuf()(stream, buf, _IOFBF, BUFSIZ)と、ヌルポインタの場合はsetvbuf()(stream, nullptr, _IONBF, 0)と等価である。

戻り値

なし。

設定に失敗したかどうかを知る必要がある場合は、setvbuf()を使用する。

備考

  • この関数は、ストリームを開いた後、入出力操作を行う前に呼び出さなければならない
  • bufとして渡す配列は、BUFSIZ個以上の要素をもち、ストリームを閉じるまで生存していなければならない

例

#include <cstdio>

int main()
{
  char buffer[BUFSIZ];

  std::FILE* fp = std::fopen("test.txt", "w");

  // 独自に用意したバッファを使用する
  std::setbuf(fp, buffer);
  std::fputs("Hello", fp);

  std::fclose(fp);
  std::printf("done\n");
}

出力

done

関連項目

  • setvbuf
  • BUFSIZ
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.