std::strstreambuf:: overflow
From cppreference.net
<
cpp
|
io
|
strstreambuf
|
protected
:
virtual int_type overflow ( int_type c = EOF ) ; |
(C++98で非推奨)
(C++26で削除) |
|
バッファの出力領域に文字 c を追加し、可能であれば再割り当てを行います。
1)
c
==
EOF
の場合、何も行いません。
2)
それ以外の場合、put領域に書き込み可能な位置がある場合(
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>
の仮想protectedメンバ関数)
|
|
[virtual]
|
出力領域から関連付けられたファイルへ文字を書き込む
(
std::basic_filebuf<CharT,Traits>
の仮想protectedメンバ関数)
|
|
1文字を出力領域に書き込み、次のポインタを進める
(
std::basic_streambuf<CharT,Traits>
のpublicメンバ関数)
|
|
|
文字を挿入する
(
std::basic_ostream<CharT,Traits>
のpublicメンバ関数)
|