std::istrstream::istrstream (3) - Linux Manuals
std::istrstream::istrstream: std::istrstream::istrstream
Command to display std::istrstream::istrstream
manual in Linux: $ man 3 std::istrstream::istrstream
NAME
std::istrstream::istrstream - std::istrstream::istrstream
Synopsis
explicit istrstream(const char* s); (1)
explicit istrstream(char* s); (2)
istrstream(const char* s, std::streamsize n); (3)
istrstream(char* s, std::streamsize n); (4)
Constructs new 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.
Parameters
s - C-string or char array to use as the contents of the stream
n - size of the array
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
See also
constructs a strstreambuf object
constructor (public member function of std::strstreambuf)
constructs an strstream, optionally allocating the buffer
constructor (public member function of std::ostrstream)
constructs an strstream, optionally allocating the buffer
constructor (public member function of std::strstream)
Pages related to std::istrstream::istrstream
- std::istrstream::rdbuf (3) - std::istrstream::rdbuf
- std::istrstream::str (3) - std::istrstream::str
- std::istrstream::~istrstream (3) - std::istrstream::~istrstream
- std::istrstream (3) - std::istrstream
- std::istream (3) - std::basic_istream
- std::istream_iterator (3) - std::istream_iterator
- std::istream_iterator<T,CharT,Traits,Distance>::istream_iterator (3) - std::istream_iterator<T,CharT,Traits,Distance>::istream_iterator
- std::istream_iterator<T,CharT,Traits,Distance>::operator*,operator-> (3) - std::istream_iterator<T,CharT,Traits,Distance>::operator*,operator->
- std::istream_iterator<T,CharT,Traits,Distance>::operator++,operator++(int) (3) - std::istream_iterator<T,CharT,Traits,Distance>::operator++,operator++(int)
- std::istream_iterator<T,CharT,Traits,Distance>::~istream_iterator (3) - std::istream_iterator<T,CharT,Traits,Distance>::~istream_iterator
- std::istreambuf_iterator (3) - std::istreambuf_iterator
- std::istreambuf_iterator<CharT,Traits>::equal (3) - std::istreambuf_iterator<CharT,Traits>::equal
- std::istreambuf_iterator<CharT,Traits>::istreambuf_iterator (3) - std::istreambuf_iterator<CharT,Traits>::istreambuf_iterator