Namespaces
Variants

std::strstreambuf:: strstreambuf

From cppreference.net
(1)
explicit strstreambuf ( std:: streamsize alsize = 0 ) ;
(C++98で非推奨)
(C++11まで)
strstreambuf ( ) : strstreambuf ( 0 ) { }
explicit strstreambuf ( std:: streamsize alsize ) ;
(C++11以降) (C++26で削除)
strstreambuf ( void * ( * palloc ) ( std:: size_t ) , void ( * pfree ) ( void * ) ) ;
(2) (C++98で非推奨)
(C++26で削除)
strstreambuf ( char * gnext, std:: streamsize n, char * pbeg = 0 ) ;
(3) (C++98で非推奨)
(C++26で削除)
strstreambuf ( signed char * gnext, std:: streamsize n, signed char * pbeg = 0 ) ;
(4) (C++98で非推奨)
(C++26で削除)
strstreambuf ( unsigned char * gnext, std:: streamsize n, unsigned char * pbeg = 0 ) ;
(5) (C++98で非推奨)
(C++26で削除)
strstreambuf ( const char * gnext, std:: streamsize n ) ;
(6) (C++98で非推奨)
(C++26で削除)
strstreambuf ( const signed char * gnext, std:: streamsize n ) ;
(7) (C++98で非推奨)
(C++26で削除)
strstreambuf ( const unsigned char * gnext, std:: streamsize n ) ;
(8) (C++98で非推奨)
(C++26で削除)
1) std::strstreambuf オブジェクトを構築する: 基底クラスを std::streambuf のデフォルトコンストラクタを呼び出して初期化し、バッファ状態を「動的」(バッファは必要に応じて割り当てられる)に設定し、割り当てサイズを指定された alsize で初期化し、割り当て関数と解放関数をnull( new [ ] delete [ ] を使用する)に初期化する。
2) std::strstreambuf オブジェクトを構築する: 基底クラスを std::streambuf のデフォルトコンストラクタを呼び出して初期化し、バッファ状態を「動的」(バッファは必要に応じて割り当てられる)に初期化し、割り当てサイズを未指定値に初期化し、割り当て関数を palloc 、解放関数を pfree に初期化する。
3-5) 以下の手順で std::strstreambuf オブジェクトを構築します:
a) 基底クラスを std::streambuf のデフォルトコンストラクタを呼び出して初期化します。
b) バッファ状態を「constant」(バッファはユーザー提供の固定サイズバッファ)に初期化します。
c) ユーザー提供の配列の要素数を次のように決定します: n がゼロより大きい場合、 n が使用されます。 n がゼロの場合、 std:: strlen ( gnext ) が実行されてバッファサイズが決定されます。 n が負の場合、 INT_MAX が使用されます。
d) 以下のように std::basic_streambuf のポインタを設定します: pbeg がヌルポインタの場合、 setg ( gnext, gnext, gnext + N ) を呼び出します。 pbeg がヌルポインタでない場合、 setg ( gnext, gnext, pbeg ) および setp ( pbeg, pbeg + N ) を実行します。ここでNは先に決定された配列の要素数です。
6-8) 次と同じ strstreambuf ( ( char * ) gnext, n ) 、ただしバッファ状態ビットマスクで"constant"ビットが設定されている点が異なる(このバッファへの出力は許可されない)。

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - その他のテキスト(Parameters, Notes, Defect reports, Example, See also)はC++関連の専門用語として翻訳せず、原文のまま保持しました - HTMLタグ、属性、クラス名、IDなどはすべて変更せず保持しました - 番号や書式設定も完全に保持しました

パラメータ

alsize - 動的に確保されるバッファの初期サイズ
palloc - ユーザー提供の割り当て関数へのポインタ
pfree - ユーザー提供の解放関数へのポインタ
gnext - ユーザー提供配列内の取得領域の先頭へのポインタ
pbeg - ユーザー提供配列内の格納領域の先頭へのポインタ
n - ユーザー提供配列の取得領域(pbegがnullの場合)または格納領域(pbegがnullでない場合)のバイト数

注記

これらのコンストラクタは通常、 std:: strstream のコンストラクタによって呼び出されます。

欠陥報告

以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR Applied to Behavior as published Correct behavior
P0935R0 C++11 デフォルトコンストラクタがexplicitであった 暗黙的とした

#include <iostream>
#include <strstream>
int main()
{
    std::strstreambuf dyn; // 動的
    std::strstream dyn_s; // 同等のストリーム
    dyn_s << 1.23 << std::ends;
    std::cout << dyn_s.str() << '\n';
    dyn_s.freeze(false);
    char buf[10];
    std::strstreambuf user(buf, 10, buf); // ユーザー提供の出力バッファ
    std::ostrstream user_s(buf, 10); // 同等のストリーム
    user_s << 1.23 << std::ends;
    std::cout << buf << '\n';
    std::strstreambuf lit("1 2 3", 5); // 定数
    std::istrstream lit_s("1 2 3"); // 同等のストリーム
    int i, j, k;
    lit_s >> i >> j >> k;
    std::cout << i << ' ' << j << ' ' << k << '\n';
}

出力:

1.23
1.23
1 2 3

関連項目

strstream オブジェクトを構築し、オプションでバッファを割り当てる
( std::strstream public member function )