名前空間
変種
操作

std::basic_stringbuf<CharT,Traits,Allocator>::basic_stringbuf

提供: cppreference.com
< cpp‎ | io‎ | basic stringbuf
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
basic_stringbuf() : basic_stringbuf(std::ios_base::in | std::ios_base::out) { }
(1)
(2)
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以上)
explicit basic_stringbuf( const std::basic_string<CharT, traits, Allocator>& new_str,

                          std::ios_base::openmode which = std::ios_base::in

                                                        | std::ios_base::out );
(3)
basic_stringbuf( const basic_stringbuf& rhs ) = delete;
(4) (C++11以上)
basic_stringbuf( basic_stringbuf&& rhs );
(5) (C++11以上)
1) デフォルトコンストラクタ。 シーケンスポインタ (eback()gptr()egptr()pbase()pptr()epptr()) がヌルポインタに初期化されるかどうかは処理系定義です。
2) std::basic_stringbuf オブジェクトを構築します。 std::basic_streambuf のデフォルトコンストラクタを呼ぶことによって基底クラスを初期化し、文字シーケンスを空文字列で初期化し、モードを which に設定します。
3) 1) と同じ初期化を行い、その後 str(new_str) を呼んだかのように紐付けられている文字シーケンスを初期化することによって、 std::basic_stringbuf オブジェクトを構築します。
4) コピーコンストラクタは削除されています。 std::basic_stringbufCopyConstructible ではありません。
5) 別の std::basic_stringbuf オブジェクト rhs からすべての状態 (紐付けられている文字列、オープンモード、ロケール、およびその他のすべての状態を含む) をムーブすることによって std::basic_stringbuf を構築します。 ムーブの後、 *this 内の std::basic_streambuf の6個のポインタは、ヌルでなければ、ムーブされた rhs 内の対応するポインタと異なることが保証されます。

目次

[編集] 引数

new_str - バッファを初期化するために使用される basic_string
rhs - 別の basic_stringbuf
which - ストリームのオープンモードを指定します。 これはビット��スク型であり、以下の定数が定義されています。
定数 説明
app 各書き込み前にストリームの終端へシークします
binary バイナリモードで開きます
in 読み込み用に開きます
out 書き込み用に開きます
trunc 開くときにストリームの内容を破棄します
ate 開いた直後にストリームの終端へシークします

[編集] ノート

一般的には std::basic_stringstream のコンストラクタによって呼ばれます。

std::ios_base::instd::ios_base::out 以外のオープンモードに対するサポートのレベルは処理系によって異なります。 C++11 は str() およびコンストラクタにおける std::ios_base::ate に対するサポートを明示的に規定していますが、 std::ios_base::appstd::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]