Library: Input/output
istrstream basic_istream basic_ios ios_base
Class that reads characters from an array in memory
#include <strstream> namespace std { class istrstream; }
The class istrstream reads characters from an array in memory. It uses a private strstreambuf object to control the associated array object. It inherits from basic_istream and therefore can use all the formatted and unformatted input functions.
NOTE -- This is a deprecated feature and might not be available in future versions.
namespace std { class istrstream : public basic_istream<char> { public: typedef char char_type; typedef char_traits<char_type> traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; explicit istrstream(const char *s); istrstream(const char *s, streamsize n); explicit istrstream(char *s); istrstream(char *s, streamsize n); virtual ~istrstream(); strstreambuf *rdbuf() const; char *str(); }; }
char_type
The type char_type is a synonym of type char.
int_type
The type int_type is a synonym of type traits_type::in_type.
off_type
The type off_type is a synonym of type traits_type::off_type.
pos_type
The type pos_type is a synonym of type traits_type::pos_type.
traits_type
The type traits_type is a synonym of type char_traits<char>.
explicit istrstream(const char* s); explicit istrstream(char* s);
Constructs an object of class istrstream, initializing the base class basic_istream with the associated strstreambuf object. The strstreambuf object is initialized by calling strstreambuf(s,0), where s designates the first element of an NTBS (null terminated byte string).
explicit istrstream(const char* s, streamsize n); explicit istrstream(char* s, streamsize n);
Constructs an object of class istrstream, initializing the base class basic_istream with the associated strstreambuf object. The strstreambuf object is initialized by calling strstreambuf(s,n), where s designates the first element of an array whose length is n elements and n is greater than zero.
virtual ~istrstream();
Destroys an object of class istrstream.
char* str();
Calls rdbuf()->str().
strstreambuf* rdbuf() const;
Returns a pointer to the private strstreambuf object associated with the stream.
// // istrstream.cpp // #include <iostream> // for cout #include <strstream> // for strstream int main () { // create two constant istrstream objects and initialize their // underlying strstreambufs with string literals; the objects // do not create copies of the literals but use them directly // for efficiency std::istrstream a ("Ce n'est pas l'homme qui prend la mer, "); std::istrstream b ("c'est la mer qui prend l'homme."); // create a dynamic strstream object std::strstream out; // output the contents of the streams into out out << a.rdbuf () << b.str () << '\n'; // output the contents of out to standard output std::cout << out.rdbuf () << '\n'; // output the contents of the stream objects to standard output std::cout << a.str () << '\n' << b.rdbuf () << '\n'; // the dtors of a and b will not release any storage // since the objects did not allocate any // the dtor of out will release allocated storage since // neither freeze() nor str() was called on the object return 0; } Program Output:
Ce n'est pas l'homme qui prend la mer, c'est la mer qui prend l'homme. Ce n'est pas l'homme qui prend la mer, c'est la mer qui prend l'homme.
char_traits, ios_base, basic_ios, strstreambuf, ostrstream, strstream
Deprecated. See ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Annex D Compatibility features Section D.7.2