Namespaces
Variants

std::basic_istringstream<CharT,Traits,Allocator>:: basic_istringstream

From cppreference.net

(注:このHTML要素には翻訳対象のテキストコンテンツが含まれていないため、元の構造をそのまま保持しています)
(1)
explicit basic_istringstream ( std:: ios_base :: openmode mode =
std:: ios_base :: in ) ;
(C++11以前)
explicit basic_istringstream ( std:: ios_base :: openmode mode ) ;
(C++11以降)
basic_istringstream ( )
: basic_istringstream ( std:: ios_base :: in ) { }
(2) (C++11以降)
explicit basic_istringstream

( const std:: basic_string < CharT, Traits, Allocator > & str,
std:: ios_base :: openmode mode =

std:: ios_base :: in ) ;
(3)
explicit basic_istringstream

( std:: basic_string < CharT, Traits, Allocator > && str,
std:: ios_base :: openmode mode =

std:: ios_base :: in ) ;
(4) (C++20以降)
basic_istringstream ( std:: ios_base :: openmode mode, const Allocator & a ) ;
(5) (C++20以降)
template < class SAlloc >

basic_istringstream ( const std:: basic_string < CharT, Traits, SAlloc > & str,

std:: ios_base :: openmode mode, const Allocator & a ) ;
(6) (C++20以降)
template < class SAlloc >

basic_istringstream ( const std:: basic_string < CharT, Traits, SAlloc > & str,
const Allocator & a )

: basic_istringstream ( str, std:: ios_base :: in , a ) { }
(7) (C++20以降)
template < class SAlloc >

explicit basic_istringstream
( const std:: basic_string < CharT, Traits, SAlloc > & str,
std:: ios_base :: openmode mode =

std:: ios_base :: in ) ;
(8) (C++20以降)
template < class StringViewLike >

explicit basic_istringstream
( const StringViewLike & t,
std:: ios_base :: openmode mode =

std:: ios_base :: in ) ;
(9) (C++26以降)
template < class StringViewLike >

basic_istringstream ( const StringViewLike & t,

std:: ios_base :: openmode mode, const Allocator & a ) ;
(10) (C++26以降)
template < class StringViewLike >
basic_istringstream ( const StringViewLike & t, const Allocator & a ) ;
(11) (C++26以降)
basic_istringstream ( basic_istringstream && other ) ;
(12) (C++11以降)

新しい文字列ストリームを構築します。

与えられた

std::basic_istream 基底クラスと 説明専用データメンバ sb は以下のように初期化されます。

オーバーロード
番号
std::basic_istream 基底クラス sb
(1) base_type ( std:: addressof ( sb ) ) [1] buf_type ( mode | std:: ios_base :: in )
(2) buf_type ( std:: ios_base :: in )
(3) buf_type ( str, mode | std:: ios_base :: in )
(4) buf_type ( std :: move ( str ) , mode | std:: ios_base :: in )
(5) buf_type ( mode | std:: ios_base :: in , a )
(6) buf_type ( str, mode | std:: ios_base :: in , a )
(7) buf_type ( str, std:: ios_base :: in , a )
(8) buf_type ( str, mode | std:: ios_base :: in )
(9) std:: addressof ( sb ) { t, mode | std:: ios_base :: in , Allocator ( ) }
(10) { t, mode | std:: ios_base :: in , a }
(11) { t, std:: ios_base :: in , a }
(12) other std::basic_istream 基底クラスからムーブ構築 other. sb からムーブ構築
  1. std::basic_iostream 基底クラスはC++11まで base_type ( & sb ) で初期化されていました(オーバーロード (1,3) の場合)。
8) このオーバーロードは、 std:: is_same_v < SAlloc, Allocator > false の場合にのみ、オーバーロード解決に参加します。
9-11) これらのオーバーロードは、以下の条件が満たされる場合にのみオーバーロード解決に参加します: std:: is_convertible_v < const StringViewLike & , std:: basic_string_view < CharT, Traits >> true である場合。

目次

パラメータ

str - 文字列ストリームの初期内容として使用する文字列
t - 文字列ストリームの初期内容として使用するオブジェクト( std::basic_string_view に変換可能)
a - 文字列ストリームの内容の割り当てに使用するアロケータ
mode - ストリームのオープンモードを指定。 BitmaskType であり、以下の定数が定義されている:
定数 説明
app 各書き込み前にストリームの終端へシーク
binary バイナリモード でオープン
in 読み取り用にオープン
out 書き込み用にオープン
trunc オープン時にストリームの内容を破棄
ate オープン直後にストリームの終端へシーク
noreplace (C++23) 排他モードでオープン
other - ソースとして使用する別の文字列ストリーム

注記

文字列変換などで使用される際のタイトなループ内での一回限りの basic_istringstream オブジェクトの構築は、 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 適用対象 公開時の動作 正しい動作
P0935R0 C++11 デフォルトコンストラクタはexplicitであった 暗黙的(implicit)に変更

関連項目

基盤となる文字列デバイスオブジェクトの内容を取得または設定する
(public member function)
basic_stringbuf オブジェクトを構築する
( std::basic_stringbuf<CharT,Traits,Allocator> のpublic member function)