Namespaces
Variants

std::istrstream:: istrstream

From cppreference.net
explicit istrstream ( const char * s ) ;
(1) (C++98で非推奨)
(C++26で削除)
explicit istrstream ( char * s ) ;
(2) (C++98で非推奨)
(C++26で削除)
istrstream ( const char * s, std:: streamsize n ) ;
(3) (C++98で非推奨)
(C++26で削除)
istrstream ( char * s, std:: streamsize n ) ;
(4) (C++98で非推奨)
(C++26で削除)

std::istrstream とその基盤となる std::strstreambuf を新しく構築します。

1,2) 基底の std::strstreambuf strstreambuf ( s, 0 ) を呼び出して構築し、基底クラスを strstreambuf のアドレスで初期化する。 s がヌル終端配列の要素を指していない場合、動作は未定義である。
3,4) 基盤となる std::strstreambuf strstreambuf ( s, n ) を呼び出して構築し、基底クラスを strstreambuf のアドレスで初期化します。 s が少なくとも n 要素の長さを持つ配列の要素を指していない場合、動作は未定義です。

パラメータ

s - ストリームの内容として使用するC文字列または文字配列
n - 配列のサイズ

#include <iostream>
#include <strstream>
int main()
{
    std::istrstream s1("1 2 3"); // 文字列リテラル
    int n1, n2, n3;
    if (s1 >> n1 >> n2 >> n3)
        std::cout << n1 << ", " << n2 << ", " << n3 << '\n';
    char arr[] = {'4', ' ', '5', ' ', '6'};
    std::istrstream s2(arr, sizeof arr);
    if (s2 >> n1 >> n2 >> n3)
        std::cout << n1 << ", " << n2 << ", " << n3 << '\n';
}

出力:

1, 2, 3
4, 5, 6

関連項目

strstreambuf オブジェクトを構築する
( std::strstreambuf のpublicメンバ関数)
ostrstream オブジェクトを構築する(オプションでバッファを割り当てる)
( std::ostrstream のpublicメンバ関数)
strstream オブジェクトを構築する(オプションでバッファを割り当てる)
( std::strstream のpublicメンバ関数)