GeezerVison is showing cpprefjp.github.io — std::basic_stringstream::str - cpprefjp C++日本語リファレンス
最終更新日時:
2026年08月25日 12時11分17秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<sstream>
std:: basic_stringstream:: str
basic_string < CharT , Traits , Allocator > str () const ; // (1) C++98
basic_string < CharT , Traits , Allocator > str () const & ; // (1) C++20
template < class SAlloc >
basic_string < CharT , Traits , SAlloc > str ( const SAlloc & sa ) const & ; // (2) C++20
basic_string < CharT , Traits , Allocator > str () const && ; // (3) C++20
void str ( const basic_string < CharT , Traits , Allocator >& s ); // (4) C++98
template < class SAlloc >
void str ( const basic_string < CharT , Traits , SAlloc >& s ); // (5) C++20
void str ( const basic_string < CharT , Traits , Allocator >&& s ); // (6) C++20
template < class T >
void str ( const T & t ); // (7) C++26
概要
文字列オブジェクトを取得または設定する。
書き込み位置としては先頭にリセットされるため注意すること。
(1) : 文字列オブジェクトを取得する
(2) : 文字列オブジェクトを取得して、SAlloc型のアロケータsaによって確保する
(3) : 保持する文字列オブジェクトをムーブして取得する
(4) : 文字列オブジェクトsを設定する
(5) : Allocatorに変換可能なSAlloc型のアロケータによって確保されているデータをコピーして、文字列オブジェクトsを設定する
(6) : 与えられた文字列オブジェクトsをムーブして設定する
(7) : std::basic_string_view に変換可能な文字列を設定する
テンプレートパラメータ制約
(7) : is_convertible_v<const T&, basic_string_view<CharT, Traits>>がtrueであること
効果
(1) : return rdbuf()->str() と等価
(2) : return rdbuf()->str(sa) と等価
(3) : return std::move(*rdbuf()).str() と等価
(4) : rdbuf()->str(s) と等価
(5) : rdbuf()->str(s) と等価
(6) : rdbuf()->str(std::move(s)) と等価
(7) : rdbuf()->str(t) と等価
例
基本的な使い方
出力
1: initial content
2: initial content + added
3: new content
Read: new
4: new content
5: Empty? yes
ムーブを使用する例 (C++20)
出力
Move string more
Move string more
string_viewからの設定 (C++26)
出力
set from string literal test
set from string_view test
関連項目
参照