std::ostrstream:: ostrstream
From cppreference.net
<
cpp
|
io
|
ostrstream
|
ostrstream
(
)
;
|
(1) |
(C++98で非推奨)
(C++26で削除) |
|
ostrstream
(
char
*
s,
int
n,
std::
ios_base
::
openmode
mode
=
std::
ios_base
::
out
)
;
|
(2) |
(C++98で非推奨)
(C++26で削除) |
新しい出力 strstream とその基盤となる std::strstreambuf を構築します。
2)
基底クラスを、基盤となる
std::strstreambuf
メンバのアドレスで初期化しました。このメンバは、ユーザー提供の固定サイズ配列に書き込む2つの可能な方法のいずれかで初期化されます:
a)
app
ビットが
mode
に設定されていない場合、
strstreambuf
(
s, n, s
)
を呼び出してバッファを構築する。
s
が指す配列の最初の要素から
n
個未満の要素しか存在しない場合、動作は未定義である。
b)
app
ビットが
mode
に設定されている場合、
strstreambuf
(
s, n, s
+
std::
strlen
(
s
)
)
を呼び出してバッファを構築する。
s
が指す先頭要素を持つ配列に
n
要素未満しか存在しない場合、または配列が有効なナル終端文字列を含まない場合、動作は未定義である。
パラメータ
| s | - | 出力バッファとして使用するchar配列 | ||||||||||||||||
| n | - | 出力バッファとして使用する配列のサイズ | ||||||||||||||||
| mode | - |
ストリームのオープンモードを指定。ビットマスク型であり、以下の定数が定義されている(ただし
app
のみ使用される):
|
例
このコードを実行
#include <iostream> #include <strstream> int main() { std::ostrstream s1; // 動的バッファ s1 << 1 << ' ' << 3.14 << " example\n" << std::ends; std::cout << s1.str(); s1.freeze(false); char arr[15] = "Hello"; std::ostrstream s2(arr, sizeof arr, std::ios_base::app); s2 << ", world!" << std::ends; std::cout << s2.str() << '\n'; std::cout << arr << '\n'; // ストリームは提供された配列を使用する }
出力:
1 3.14 example Hello, world! Hello, world!
関連項目
strstreambuf
オブジェクトを構築する
(
std::strstreambuf
のpublicメンバ関数)
|
|
istrstream
オブジェクトを構築する(オプションでバッファを割り当てる)
(
std::istrstream
のpublicメンバ関数)
|
|
strstream
オブジェクトを構築する(オプションでバッファを割り当てる)
(
std::strstream
のpublicメンバ関数)
|