名前空間
変種
操作

std::strstreambuf::overflow

From cppreference.com
< cpp‎ | io‎ | strstreambuf
 
 
 
 
protected:
virtual int_type overflow( int_type c = EOF );
(C++98で非推奨)
(C++26で削除)

バッファの書き込み領域に文字 c を追加します。可能であれば再割り当てを行います。

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

目次

[編集] パラメータ

c - 出力領域に格納する文字

[編集] 戻り値

c == EOF の場合、EOF 以外の値を返します。それ以外の場合、成功時は (unsigned char)(c) を返し、失敗時は EOF を返します。

[編集]

#include <iostream>
#include <strstream>
 
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

[編集] 関連項目

[virtual]
関連付けられた出力シーケンスに、配置領域から文字を書き込む
(std::basic_streambuf<CharT,Traits> の仮想 protected メンバ関数) [編集]
[virtual]
出力シーケンスに文字を追加する
(std::basic_stringbuf<CharT,Traits,Allocator> の仮想保護メンバ関数) [編集]
[virtual]
ファイルバッファの格納領域から、関連付けられたファイルへ文字を書き込みます。
(std::basic_filebuf<CharT,Traits> の保護仮想メンバ関数) [編集]
配置領域に1文字を書き込み、次のポインタを進める
(std::basic_streambuf<CharT,Traits> の public メンバ関数) [編集]
文字を挿入する
(std::basic_ostream<CharT,Traits> の public メンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)