名前空間
変種

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

提供: cppreference.com

[edit template]
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
<tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody>
basic_stringstream() : basic_stringstream(std::ios_base::in | std::ios_base::out) { }
(1) (C++11以上)
(2)
explicit basic_stringstream( std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out );
(C++11未満)
explicit basic_stringstream( std::ios_base::openmode mode );
(C++11以上)
explicit basic_stringstream( const std::basic_string<CharT,Traits,Allocator>& str, {{#pad:|27}} std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out );
(3)
basic_stringstream( basic_stringstream&& other );
(4) (C++11以上)
basic_stringstream( std::ios_base::openmode mode, const Allocator& a );
(5) (C++20以上)
explicit basic_stringstream( std::basic_string<CharT,Traits,Allocator>&& str, {{#pad:|27}} std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out );
(6) (C++20以上)
template<class SAlloc> basic_stringstream( const std::basic_string<CharT,Traits,SAlloc>& str, {{#pad:|18}} const Allocator& a ) : basic_stringstream(str, std::ios_base::in | std::ios_base::out, a) { }
(7) (C++20以上)
template<class SAlloc> basic_stringstream( const std::basic_string<CharT,Traits,SAlloc>& str, {{#pad:|18}} std::ios_base::openmode mode, const Allocator& a );
(8) (C++20以上)
template<class SAlloc> explicit basic_stringstream( const std::basic_string<CharT,Traits,SAlloc>& str, {{#pad:|27}} std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out );
(9) (C++20以上)

新しい文字列ストリームを構築します。

1) デフォルトコンストラクタ。 デフォルトのオープンモードを使用して新しいベースとなる文字列デバイスを構築します。
2) ベースとなる新しい文字列デバイスを構築します。 ベースとなる basic_stringbuf オブジェクトは basic_stringbuf<Char,Traits,Allocator>(mode) のように構築されます。
3) ベースとなる文字列デバイスの初期内容として str のコピーを使用します。 ベースとなる basic_stringbuf オブジェクトは basic_stringbuf<Char,Traits,Allocator>(str, mode) のように構築されます。
4) ムーブコンストラクタ。 ムーブセマンティクスを用いて other の状態を持つ文字列ストリームを構築します。
5) 新しいベースとなる文字列デバイスを構築します。 ベースとなる basic_stringbuf オブジェクトは basic_stringbuf<Char,Traits,Allocator>(mode, a) のように構築されます。
6) str を用いてベースとなる文字列の内容をムーブ構築します。 ベースとなる basic_stringbuf オブジェクトは basic_stringbuf<Char,Traits,Allocator>(std::move(str), mode) のように構築されます。
7) 新しいベースとなる文字列デバイスを構築します。 ベースとなる basic_stringbuf オブジェクトは basic_stringbuf<Char,Traits,Allocator>(str, std::ios_base::in | std::ios_base::out, a) のように構築されます。
8) 新しいベースとなる文字列デバイスを構築します。 ベースとなる basic_stringbuf オブジェクトは basic_stringbuf<Char,Traits,Allocator>(str, mode, a) のように構築されます。
9) 新しいベースとなる文字列デバイスを構築します。 ベースとなる basic_stringbuf オブジェクトは basic_stringbuf<Char,Traits,Allocator>(str, mode) のように構築されます。 このオーバーロードは、SAllocAllocator が同じ型でない場合にのみ、オーバーロード解決に参加します。

引数

str - 文字列ストリームの初期内容として使用する文字列
a - 文字列ストリームの内容を確保するための使用するアロケータ
mode - ストリームのオープンモードを指定します。 これはビットマスク型であり、以下の定数が定義されています。
定数 説明
app 各書き込み前にストリームの終端へシークします
binary バイナリモードで開きます
in 読み込み用に開きます
out 書き込み用に開きます
trunc 開くときにストリームの内容を破棄します
ate 開いた直後にストリームの終端へシークします
other - ソースとして使用する別の文字列ストリーム

ノート

文字列変換のために使用するときなどに、タイトなループ内で使い捨ての basic_stringstream オブジェクトを構築することは、同じオブジェクトを再利用するために str を呼ぶよりも、非常に高コストになる可能性があります。

欠陥報告

以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。

DR 適用先 発行時の動作 正しい動作
P0935R0 C++11 default constructor was explicit made implicit

#include <iostream>
#include <sstream>
int main()
{
    // default constructor (input/output stream)
    std::stringstream buf1;
    buf1 << 7;
    int n = 0;
    buf1 >> n;
    std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n';

    // input stream
    std::istringstream inbuf("-10");
    inbuf >> n;
    std::cout << "n = " << n << '\n';

    // output stream in append mode (C++11)
    std::ostringstream buf2("test", std::ios_base::ate);
    buf2 << '1';
    std::cout << buf2.str() << '\n';
}

出力:

buf1 = 7 n = 7
n = -10
test1

関連項目

ベースとなる文字列デバイスオブジェクトを取得または設定します
(パブリックメンバ関数) [edit]
basic_stringbuf オブジェクトを構築します
(std::basic_stringbuf<CharT,Traits,Allocator>のパブリックメンバ関数) [edit]