GeezerVison is showing cpprefjp.github.io — std::basic_stringstream::コンストラクタ - cpprefjp C++日本語リファレンス
最終更新日時:
2026年08月25日 12時11分17秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<sstream>
std:: basic_stringstream:: コンストラクタ
basic_stringstream ()
: basic_stringstream ( ios_base :: in | ios_base :: out ) {} // (1) C++11
explicit basic_stringstream (
ios_base :: openmode which ); // (2) C++11
explicit basic_stringstream (
ios_base :: openmode which = ios_base :: in | ios_base :: out ); // (1)+(2) C++98
explicit basic_stringstream (
const basic_string < CharT , Traits , Allocator >& s ,
ios_base :: openmode which = ios_base :: in | ios_base :: out ); // (3) C++98
explicit basic_stringstream (
basic_string < CharT , Traits , Allocator >&& s ,
ios_base :: openmode which = ios_base :: in | ios_base :: out ); // (4) C++20
basic_stringstream ( ios_base :: openmode which , const Allocator & a ); // (5) C++20
explicit basic_stringstream (
const basic_string < CharT , Traits , Allocator >& s ,
const Allocator & a )
: basic_stringstream ( s , ios_base :: in | ios_base :: out , a ) {} // (6) C++20
explicit basic_stringstream (
const basic_string < CharT , Traits , Allocator >& s ,
ios_base :: openmode which ,
const Allocator & a ); // (7) C++20
template < class SAlloc >
explicit basic_stringstream (
const basic_string < CharT , Traits , SAlloc >& s ,
ios_base :: openmode which = ios_base :: in | ios_base :: out ); // (8) C++20
template < class SAlloc >
basic_stringstream (
const basic_string < CharT , Traits , SAlloc >& s ,
const Allocator & a )
: basic_stringstream ( s , ios_base :: in | ios_base :: out , a ) {} // (9) C++20
template < class SAlloc >
basic_stringstream (
const basic_string < CharT , Traits , SAlloc >& s ,
ios_base :: openmode which ,
const Allocator & a ); // (10) C++20
basic_stringstream ( basic_stringstream && rhs ); // (11) C++11
template < class T >
explicit basic_stringstream (
const T & t ,
ios_base :: openmode which = ios_base :: in | ios_base :: out ); // (12) C++26
template < class T >
basic_stringstream (
const T & t ,
const Allocator & a ); // (13) C++26
template < class T >
basic_stringstream ( const T & t ,
ios_base :: openmode which ,
const Allocator & a ); // (14) C++26
概要
basic_stringstreamオブジェクトを構築する。
ここで、初期値として設定する文字列は、既存のファイルを上書きモードで開くことに似ており、ストリームの初期位置が先頭のまま、ストリーム内容の文字列を設定するものである。
テンプレートパラメータ制約
(12), (13), (14) : is_convertible_v<const T&, basic_string_view<CharT, Traits>>がtrueであること
効果
(1) : 内部のbasic_stringbufオブジェクトをbasic_stringbuf<CharT, Traits, Allocator>(ios_base::in | ios_base::out)で構築する
(2) : 内部のbasic_stringbufオブジェクトをbasic_stringbuf<CharT, Traits, Allocator>(which)で構築する
(3) : 内部のbasic_stringbufオブジェクトをbasic_stringbuf<CharT, Traits, Allocator>(s, which)で構築する
(4) : 内部のbasic_stringbufオブジェクトをbasic_stringbuf<CharT, Traits, Allocator>(std::move(s), which)で構築する
(5) : 内部のbasic_stringbufオブジェクトをbasic_stringbuf<CharT, Traits, Allocator>(which, a)で構築する
(6), (7), (8), (9), (10) : 各引数は対応するbasic_stringbufのコンストラクタに渡される
(11) : rhsからbasic_stringstreamオブジェクトをムーブ構築する
(12) : basic_string_view<CharT, Traits>(t)で文字列を初期化し、モードはwhichに設定する
(13) : basic_string_view<CharT, Traits>(t)で文字列を初期化し、モードはios_base::in | ios_base::out、アロケータはaに設定する
(14) : basic_string_view<CharT, Traits>(t)で文字列を初期化し、モードはwhich、アロケータはaに設定する
例
基本的な使い方
出力
hello
initial value added
string_viewからの構築 (C++26)
出力
Hello?World
World?
参照