Name

strstream class — Input and output character array streams

Synopsis

class strstream: public iostream
{
public:
  typedef char char_type;
  typedef typename char_traits<char>::int_type int_type;
  typedef typename char_traits<char>::pos_type pos_type;
  typedef typename char_traits<char>::off_type off_type;
   
  strstream(  );
  strstream(char* s, int n, 
            ios_base::openmode mode = ios_base::in|ios_base::out);
  virtual ~strstream(  );
   
  strstreambuf* rdbuf(  ) const;
  void freeze(bool freezefl = true);
  int pcount(  ) const;
  char* str(  );
};

The strstream class is a stream class that performs input and output to a character array. You can start with an empty string and write to the stream, or start with a string and read from the stream. You can switch between reading and writing at any time. If you use the default constructor and write to the stream, the stream buffer grows as needed. Then you can call str( ) to obtain the resulting character array. Once you call str( ), the stream is frozen and cannot be modified. The pointer returned from str( ) remains valid until the ostrstream object is destroyed or until you thaw the stream to allow writing again.

The following are the methods of strstream:

strstream ( )

Initializes an empty string stream by constructing an internal strstreambuf object and passing the address of the string buffer to the base-class constructor for iostream.

basic_strstream (char* str, int n, ios_base::openmode mode = ios_base::in|ios_base::out)

Initializes a string stream with str ...

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.