std::basic_stringbuf<CharT,Traits,Allocator>:: basic_stringbuf
| (1) | ||
|
explicit
basic_stringbuf
(
std::
ios_base
::
openmode
which
=
std:: ios_base :: in | std:: ios_base :: out ) ; |
(C++11まで) | |
|
explicit
basic_stringbuf
(
std::
ios_base
::
openmode
which
)
;
|
(C++11以降) | |
|
basic_stringbuf
(
)
: basic_stringbuf ( std:: ios_base :: in | std:: ios_base :: out ) { } |
(2) | (C++11以降) |
|
explicit
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
s,
|
(3) | |
|
explicit
basic_stringbuf
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
s,
std::
ios_base
::
openmode
which
=
|
(4) | (C++20以降) |
|
basic_stringbuf
(
std::
ios_base
::
openmode
which,
const
Allocator
&
a
)
;
|
(5) | (C++20以降) |
|
explicit
basic_stringbuf
(
const
Allocator
&
a
)
: basic_stringbuf ( std:: ios_base :: in | std:: ios_base :: out , a ) { } |
(6) | (C++20以降) |
|
template
<
class
SAlloc
>
explicit
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(7) | (C++20以降) |
|
template
<
class
SAlloc
>
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(8) | (C++20以降) |
|
template
<
class
SAlloc
>
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(9) | (C++20以降) |
|
template
<
class
StringViewLike
>
explicit
basic_stringbuf
(
const
StringViewLike
&
t,
|
(10) | (C++26以降) |
|
template
<
class
StringViewLike
>
basic_stringbuf
(
const
StringViewLike
&
t,
|
(11) | (C++26以降) |
|
template
<
class
StringViewLike
>
basic_stringbuf ( const StringViewLike & t, const Allocator & a ) ; |
(12) | (C++26以降) |
|
basic_stringbuf
(
basic_stringbuf
&&
rhs
)
;
|
(13) | (C++11以降) |
|
basic_stringbuf
(
basic_stringbuf
&&
rhs,
const
Allocator
&
a
)
;
|
(14) | (C++20以降) |
|
basic_stringbuf
(
const
basic_stringbuf
&
rhs
)
=
delete
;
|
(15) | (C++11以降) |
std::basic_streambuf
基底クラスおよび
説明専用データメンバ
buf
と
mode
は以下のように初期化されます。
これらの部分オブジェクトの初期化後、オーバーロード
(3-12)
は、
init_buf_ptrs
()
を呼び出すかのように入力シーケンスと出力シーケンスを初期化します。
| オーバーロード | std::basic_streambuf 基底 |
buf
|
mode
|
|---|---|---|---|
| (1) | デフォルト初期化 |
実装定義
(下記参照) |
which |
| (2) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (3) | s | which | |
| (4) | std :: move ( s ) | ||
| (5) | a | ||
| (6) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (7) | s | which | |
| (8) | { s, a } | ||
| (9) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (10) | { sv, Allocator ( ) } | which | |
| (11) | { sv, a } | ||
| (12) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (13) |
rhs
コピー構築 |
std :: move ( rhs ) . str ( ) | rhs. mode |
| (14) | { std :: move ( rhs ) . str ( ) , a } |
std:: basic_string_view < CharT, Traits >> が true である場合にのみ、オーバーロード解決に参加します。
- Let rhs_p がこの構築直前の rhs の状態を参照するものとすると、以下の式は true と評価されます:
-
- str ( ) == rhs_p. str ( )
- getloc ( ) == rhs_p. getloc ( )
- gptr ( ) - eback ( ) == rhs_p. gptr ( ) - rhs_p. eback ( )
- egptr ( ) - eback ( ) == rhs_p. egptr ( ) - rhs_p. eback ( )
- pptr ( ) - pbase ( ) == rhs_p. pptr ( ) - rhs_p. pbase ( )
- epptr ( ) - pbase ( ) == rhs_p. epptr ( ) - rhs_p. pbase ( )
タグ内のC++コード、C++専門用語はすべて原文のまま保持されています。翻訳対象となる自然言語テキストが存在しないため、出力は入力と同一です)
- rhs_a をこの構築直後の rhs の状態とすると、以下の式は true と評価されます:
-
- ! eback ( ) || eback ( ) ! = rhs_a. eback ( )
- ! gptr ( ) || gptr ( ) ! = rhs_a. gptr ( )
- ! egptr ( ) || egptr ( ) ! = rhs_a. egptr ( )
- ! pbase ( ) || pbase ( ) ! = rhs_a. pbase ( )
- ! pptr ( ) || pptr ( ) ! = rhs_a. pptr ( )
- ! epptr ( ) || epptr ( ) ! = rhs_a. epptr ( )
目次 |
パラメータ
| s | - | バッファの初期化に使用される std::basic_string | ||||||||||||||||
| t | - | バッファの初期化に使用されるオブジェクト( std::basic_string_view に変換可能) | ||||||||||||||||
| a | - | 内部の std::basic_string を構築するために使用される別のアロケータ | ||||||||||||||||
| rhs | - |
別の
basic_stringbuf
|
||||||||||||||||
| which | - |
ストリームのオープンモードを指定する。ビットマスク型であり、以下の定数が定義されている:
|
注記
通常は std::basic_stringstream のコンストラクタによって呼び出されます。
std::ios_base::in および std::ios_base::out 以外のオープンモードに対するサポートレベルは実装によって異なります。C++11では std::ios_base::ate のサポートが str() およびこのコンストラクタで明示的に規定されていますが、 std::ios_base::app 、 std::ios_base::trunc 、および std::ios_base::binary は実装によって異なる効果を持ちます。
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | 文字列ストリームと std::string_view の連携 |
例
std::basic_stringbuf
のコンストラクタを直接呼び出す例を示します:
#include <iostream> #include <sstream> int main() { // デフォルトコンストラクタ (mode = in | out) std::stringbuf buf1; buf1.sputc('1'); std::cout << &buf1 << '\n'; // 文字列コンストラクタ in at-end mode (C++11) std::stringbuf buf2("test", std::ios_base::in | std::ios_base::out | std::ios_base::ate); buf2.sputc('1'); std::cout << &buf2 << '\n'; // append mode test (results differ among compilers) std::stringbuf buf3("test", std::ios_base::in | std::ios_base::out | std::ios_base::app); buf3.sputc('1'); buf3.pubseekpos(1); buf3.sputc('2'); std::cout << &buf3 << '\n'; }
出力:
1 test1 est12 (Sun Studio) 2st1 (GCC)
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 432 | C++98 |
1. オーバーロード
(1)
は配列オブジェクトを割り当てなかった
2. オーバーロード (3) は入力シーケンスと出力シーケンスの 初期化方法を指定していなかった |
1. 制限を削除
2. 指定を追加 |
| LWG 562 | C++98 |
オーバーロード
(3)
は
epptr()
を最後の基盤となる文字の
1つ後ろを指すように設定した( bool ( which & std:: ios_base :: out ) == true の場合) |
epptr()
はその位置を
超えて設定可能 |
| P0935R0 | C++11 | デフォルトコンストラクタがexplicitだった | implicitに変更 |
関連項目
|
文字列ストリームを構築する
(
std::basic_stringstream<CharT,Traits,Allocator>
の公開メンバ関数)
|