Name

ostrstream class — Output character array streams

Synopsis

class ostrstream: public ostream
{
public:
  ostrstream(  );
  ostrstream(char* str, int n, ios_base::openmode mode = ios_base::out);
   
  strstreambuf* rdbuf(  ) const;
  void freeze(bool flag = true);
  char* str(  );
  int pcount(  ) const;
};

The ostrstream class represents an output string stream. You can provide a character array, and the stream contents are written to that array. Another typical usage is to construct an ostrstream with no argument and let the string stream allocate the string as you write to the stream. Then 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 ostrstream:

ostrstream ( )

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

ostrstream (char* str, int n, ios_base::openmode mode = ios_base::out)

Initializes a string stream with str as the initial string contents by constructing an internal strstreambuf object and passing the address of the buffer to the base-class constructor for ostream. If the ios_base::app bit is set in mode, the buffer is constructed like this:

strstreambuf(str, n, str + std::strlen(str));

If the ios_base::app bit is clear in ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.