std::basic_stringstream<CharT,Traits,Allocator>::basic_stringstream
提供: cppreference.com
<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) のように構築されます。 このオーバーロードは、SAlloc と Allocator が同じ型でない場合にのみ、オーバーロード解決に参加します。引数
| str | - | 文字列ストリームの初期内容として使用する文字列 | ||||||||||||||
| a | - | 文字列ストリームの内容を確保するための使用するアロケータ | ||||||||||||||
| mode | - | ストリームのオープンモードを指定します。 これはビットマスク型であり、以下の定数が定義されています。
| ||||||||||||||
| other | - | ソースとして使用する別の文字列ストリーム |
ノート
文字列変換のために使用するときなどに、タイトなループ内で使い捨ての basic_stringstream オブジェクトを構築することは、同じオブジェクトを再利用するために str を呼ぶよりも、非常に高コストになる可能性があります。
欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
| DR | 適用先 | 発行時の動作 | 正しい動作 |
|---|---|---|---|
| P0935R0 | C++11 | default constructor was explicit | made implicit |
例
Run this code
#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
関連項目
| ベースとなる文字列デバイスオブジェクトを取得または設定します (パブリックメンバ関数) | |
| basic_stringbuf オブジェクトを構築します ( std::basic_stringbuf<CharT,Traits,Allocator>のパブリックメンバ関数)
|