std::basic_ostringstream<CharT,Traits,Allocator>:: basic_ostringstream
| (1) | ||
|
explicit
basic_ostringstream
(
std::
ios_base
::
openmode
mode
=
std:: ios_base :: out ) ; |
(C++11まで) | |
|
explicit
basic_ostringstream
(
std::
ios_base
::
openmode
mode
)
;
|
(C++11以降) | |
|
basic_ostringstream
(
)
: basic_ostringstream ( std:: ios_base :: out ) { } |
(2) | (C++11以降) |
|
explicit
basic_ostringstream
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
str,
|
(3) | |
|
explicit
basic_ostringstream
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
str,
|
(4) | (C++20以降) |
|
basic_ostringstream
(
std::
ios_base
::
openmode
mode,
const
Allocator
&
a
)
;
|
(5) | (C++20以降) |
|
template
<
class
SAlloc
>
basic_ostringstream
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
str,
|
(6) | (C++20以降) |
|
template
<
class
SAlloc
>
basic_ostringstream
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
str,
|
(7) | (C++20以降) |
|
template
<
class
SAlloc
>
explicit
basic_ostringstream
|
(8) | (C++20以降) |
|
template
<
class
StringViewLike
>
explicit
basic_ostringstream
|
(9) | (C++26以降) |
|
template
<
class
StringViewLike
>
basic_ostringstream
(
const
StringViewLike
&
t,
|
(10) | (C++26以降) |
|
template
<
class
StringViewLike
>
basic_ostringstream ( const StringViewLike & t, const Allocator & a ) ; |
(11) | (C++26以降) |
|
basic_ostringstream
(
basic_ostringstream
&&
other
)
;
|
(12) | (C++11以降) |
新しい文字列ストリームを構築します。
与えられた
-
base_typeを std:: basic_ostream < CharT, Traits > として、および -
buf_typeを std:: basic_stringbuf < CharT, Traits, Allocator > として定義します。
std::basic_ostream
基底クラスと
説明専用データメンバ
sb
は以下のように初期化されます。
|
オーバーロード
番号 |
std::basic_ostream 基底クラス |
sb
|
|---|---|---|
| (1) | base_type ( std:: addressof ( sb ) ) [1] | buf_type ( mode | std:: ios_base :: out ) |
| (2) | buf_type ( std:: ios_base :: out ) | |
| (3) | buf_type ( str, mode | std:: ios_base :: out ) | |
| (4) | buf_type ( std :: move ( str ) , mode | std:: ios_base :: out ) | |
| (5) | buf_type ( mode | std:: ios_base :: out , a ) | |
| (6) | buf_type ( str, mode | std:: ios_base :: out , a ) | |
| (7) | buf_type ( str, std:: ios_base :: out , a ) | |
| (8) | buf_type ( str, mode | std:: ios_base :: out ) | |
| (9) | std:: addressof ( sb ) | { t, mode | std:: ios_base :: out , Allocator ( ) } |
| (10) | { t, mode | std:: ios_base :: out , a } | |
| (11) | { t, std:: ios_base :: out , a } | |
| (12) | other の std::basic_ostream 基底クラスからムーブ構築 | other. sb からムーブ構築 |
- ↑ std::basic_iostream 基底クラスはC++11まで base_type ( & sb ) で初期化されていました(オーバーロード (1,3) の場合)。
目次 |
パラメータ
| str | - | 文字列ストリームの初期内容として使用する文字列 | ||||||||||||||||
| t | - | 文字列ストリームの初期内容として使用するオブジェクト( std::basic_string_view に変換可能) | ||||||||||||||||
| a | - | 文字列ストリームの内容の割り当てに使用するアロケータ | ||||||||||||||||
| mode | - |
ストリームのオープンモードを指定。
BitmaskType
であり、以下の定数が定義されている:
|
||||||||||||||||
| other | - | ソースとして使用する別の文字列ストリーム |
注記
ワンオフの
basic_ostringstream
オブジェクトの構築を、文字列変換に使用される場合などのタイトループ内で行うことは、
str()
を呼び出して同じオブジェクトを再利用するよりも、大幅にコストが高くなる可能性があります。
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | std::stringstream と std::string_view のインターフェース連携 ( 9-11 ) |
例
#include <iostream> #include <sstream> int main() { // デフォルトコンストラクタ(入出力ストリーム) std::stringstream buf1; buf1 << 7; int n = 0; buf1 >> n; std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n'; // 入力ストリーム std::istringstream inbuf("-10"); inbuf >> n; std::cout << "n = " << n << '\n'; // 追加モードでの出力ストリーム (C++11) std::ostringstream buf2("test", std::ios_base::ate); buf2 << '1'; std::cout << buf2.str() << '\n'; }
出力:
buf1 = 7 n = 7 n = -10 test1
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| P0935R0 | C++11 | デフォルトコンストラクタは明示的でした | 暗黙的になりました |
関連項目
|
基になる文字列デバイスオブジェクトの内容を取得または設定する
(公開メンバ関数) |
|
basic_stringbuf
オブジェクトを構築する
(
std::basic_stringbuf<CharT,Traits,Allocator>
の公開メンバ関数)
|