std::istrstream::istrstream
From cppreference.com
 
 
 < cpp | io | istrstream 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Input/output library 
 
 
 
 
 
 
 
 
 
 
 
 
 Print functions (C++23)
 Buffers
(C++23)
(C++98/26*)
(C++20)
 Streams
 Abstractions
 File I/O
 String I/O
 Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
 Synchronized Output
(C++20)
 Types
 Error category interface
(C++11)
(C++11)
explicit istrstream( const char* s );
 (1) 
 (deprecated in C++98) (removed in C++26)
explicit istrstream( char* s );
 (2) 
 (deprecated in C++98) (removed in C++26)
Constructs new std::istrstream and its underlying std::strstreambuf .
1,2) Constructs the underlying std::strstreambuf  by calling strstreambuf(s, 0) and initializes the base class with the address of the 
strstreambuf. The behavior is undefined if s is not pointing at an element of a null-terminated array.3,4) Constructs the underlying std::strstreambuf  by calling strstreambuf(s, n) and initializes the base class with the address of the 
strstreambuf. The behavior is undefined if s is not pointing at an element of an array whose length is at least n elements.[edit] Parameters
 s
 -
 C-string or char array to use as the contents of the stream
 n
 -
 size of the array
[edit] Example
Run this code
#include <iostream> #include <strstream> int main() { std::istrstream s1("1 2 3"); // string literal 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'; }
Output:
1, 2, 3 4, 5, 6
[edit] See also
 
 constructs an 
(public member function of
ostrstream object, optionally allocating the buffer (public member function of
std::ostrstream) [edit] 
 
 constructs a 
(public member function of
strstream object, optionally allocating the buffer (public member function of
std::strstream) [edit]