最終更新日時:
が更新

履歴 編集

function
<fstream>

std::basic_filebuf::showmanyc

protected:
  virtual streamsize showmanyc();  // (1) C++03
  streamsize showmanyc() override; // (1) C++17

概要

ブロックせずに読み取れると期待される文字数を得る。

このメンバ関数はprotectedであり、std::basic_streambufpublicメンバ関数in_avail()を通して間接的に呼び出される。

効果

basic_streambuf::showmanyc()と同じ動作をする。

戻り値

basic_streambuf::showmanyc()と同じ。

備考

処理系は、入力シーケンスからさらに文字を読み取れるかどうかを判断できる場合、この関数シグニチャに対するオーバーライド定義を提供してもよい。

#include <iostream>
#include <fstream>

int main()
{
  {
    std::filebuf out;
    out.open("test.txt", std::ios_base::out);
    out.sputn("ABCDE", 5);
  }

  std::filebuf buf;
  buf.open("test.txt", std::ios_base::in);

  // get領域に文字を読み込む
  buf.sgetc();

  // 読み込み済みの領域に残っている文字数を得る
  std::cout << (buf.in_avail() > 0) << std::endl;
}

出力

1

バージョン

言語

  • C++98

関連項目