std::basic_stringbuf<CharT,Traits,Allocator>::basic_stringbuf - cppreference.com
提供: cppreference.com
<tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody>
|
|
(1) | |
| (2) | ||
|
|
(C++11未満) | |
|
|
(C++11以上) | |
|
|
(3) | |
|
|
(4) | (C++11以上) |
|
|
(5) | (C++11以上) |
1) デフォルトコンストラクタ。 シーケンスポインタ (eback()、 gptr()、 egptr()、 pbase()、 pptr()、 epptr()) がヌルポインタに初期化されるかどうかは処理系定義です。
2) std::basic_stringbuf オブジェクトを構築します。 std::basic_streambuf のデフォルトコンストラクタを呼ぶことによって基底クラスを初期化し、文字シーケンスを空文字列で初期化し、モードを which に設定します。
3) 1) と同じ初期化を行い、その後 str を呼んだかのように紐付けられている文字シーケンスを初期化することによって、 std::basic_stringbuf オブジェクトを構築します。
4) コピーコンストラクタは削除されています。 std::basic_stringbuf は CopyConstructible ではありません。
5) 別の std::basic_stringbuf オブジェクト rhs からすべての状態 (紐付けられている文字列、オープンモード、ロケール、およびその他のすべての状態を含む) をムーブすることによって std::basic_stringbuf を構築します。 ムーブの後、 *this 内の std::basic_streambuf の6個のポインタは、ヌルでなければ、ムーブされた rhs 内の対応するポインタと異なることが保証されます。
引数
| new_str | - | バッファを初期化するために使用される basic_string
| ||||||||||||||
| rhs | - | 別の basic_stringbuf
| ||||||||||||||
| which | - | ストリームのオープンモードを指定します。 これはビットマスク型であり、以下の定数が定義されています。
|
ノート
一般的には std::basic_stringstream のコンストラクタによって呼ばれます。
std::ios_base::in と std::ios_base::out 以外のオープンモードに対するサポートのレベルは処理系によって異なります。 C++11 は str() およびコンストラクタにおける std::ios_base::ate に対するサポートを明示的に規定していますが、 std::ios_base::app、 std::ios_base::trunc および std::ios_base::binary は処理系によって異なる効果を持ちます。
欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
| DR | 適用先 | 発行時の動作 | 正しい動作 |
|---|---|---|---|
| P0935R0 | C++11 | default constructor was explicit | made implicit |
例
basic_stringbuf のコンストラクタの直接呼び出しをデモンストレーションします。
#include <iostream> #include <sstream> int main() { // default constructor (mode = in|out) std::stringbuf buf1; buf1.sputc('1'); std::cout << &buf1 << '\n'; // string constructor 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)
関連項目
| 文字列ストリームを構築します ( std::basic_stringstream<CharT,Traits,Allocator>のパブリックメンバ関数) [edit]
|