名前空間
変種
操作

std::strstreambuf::overflow

提供: cppreference.com
< cpp‎ | io‎ | strstreambuf
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
protected:
virtual int_type overflow (int_type c = EOF);

可能であれば再確保を行い、バッファの put 領域に文字 c を追加します。

1) c==EOF の場合は、何もしません。
2) そうでなく、 put 領域に利用可能な書き込み位置があれば (pptr() < epptr())、 *pptr()++ = c によって行われたかのように、その文字を格納します。
3) そうでなく、ストリームバッファのモードが動的でないか、ストリームバッファが現在凍結されていれば、関数は失敗し、 EOF を返します。
4) そうでなければ、現在の動的配列の内容 (もしあれば) と少なくともひとつの追加の書き込み位置を保持するのに十分大きな動的配列を再確保 (または初期確保) します。 コンストラクタで確保関数へのポインタ palloc が使用された場合は、その関数が (*palloc)(n) で呼ばれ、そうでなければ new char[n] が使用されます。 ただし n は確保するバイト数です。 コンストラクタで解放関数へのポインタ pfree が使用された場合は、必要であれば前の配列を解放するためにその関数が (*pfree)(p) で呼ばれ、そうでなければ delete[] p が使用されます。 確保が失敗した場合、関数は失敗し、 EOF を返します。

目次

[編集] 引数

c - put 領域に格納する文字

[編集] 戻り値

c==EOF の場合は、 EOF 以外の何らかの値を返します。 そうでなければ、成功した場合は (unsigned char)(c)、そうでなければ EOF を返します。

[編集]

#include <strstream>
#include <iostream>
 
struct mybuf : std::strstreambuf
{
    int_type overflow(int_type c) 
    {
        std::cout << "Before overflow(): size of the put area is " << epptr()-pbase()
                  << " with " << epptr()-pptr() << " write positions available\n";
        int_type rc = std::strstreambuf::overflow(c);
        std::cout << "After overflow(): size of the put area is " << epptr()-pbase()
                  << " with " << epptr()-pptr() << " write positions available\n";
        return rc;
    }
};
 
int main()
{
    mybuf sbuf; // read-write dynamic strstreambuf
    std::iostream stream(&sbuf);
 
    stream << "Sufficiently long string to overflow the initial allocation, at least "
           << " on some systems.";
}

出力例:

Before overflow(): size of the put area is 16 with 0 write positions available
After overflow(): size of the put area is 32 with 15 write positions available
Before overflow(): size of the put area is 32 with 0 write positions available
After overflow(): size of the put area is 64 with 31 write positions available
Before overflow(): size of the put area is 64 with 0 write positions available
After overflow(): size of the put area is 128 with 63 write positions available

[編集] 関連項目

[仮想]
put 領域から紐付けられている出力シーケンスに文字を書き込みます
(std::basic_streambuf<CharT,Traits>の仮想プロテクテッドメンバ関数) [edit]
[仮想]
出力シーケンスに文字を追加します
(std::basic_stringbuf<CharT,Traits,Allocator>の仮想プロテクテッドメンバ関数) [edit]
[仮想]
put 領域から紐付けられているファイルに文字を書き込みます
(std::basic_filebuf<CharT,Traits>の仮想プロテクテッドメンバ関数) [edit]
文字をひとつ put 領域に書き込み、次ポインタを進めます
(std::basic_streambuf<CharT,Traits>のパブリックメンバ関数) [edit]
文字を挿入します
(std::basic_ostream<CharT,Traits>のパブリックメンバ関数) [edit]