Go to the first, previous, next, last section, table of contents.

Reading and writing in memory

The classes istrstream, ostrstream, and strstream provide some additional features for reading and writing strings in memory--both static strings, and dynamically allocated strings. The underlying class strstreambase provides some features common to all three; strstreambuf underlies that in turn.

Constructor: istrstream::istrstream (const char* str [, int size])

Associate the new input string class istrstream with an existing static string starting at str, of size size. If you do not specify size, the string is treated as a NUL terminated string.

Constructor: ostrstream::ostrstream ()

Create a new stream for output to a dynamically managed string, which will grow as needed.

Constructor: ostrstream::ostrstream (char* str, int size [,int mode])

A new stream for output to a statically defined string of length size, starting at str. You may optionally specify one of the modes described for ifstream::ifstream; if you do not specify one, the new stream is simply open for output, with mode ios::out.

Method: int ostrstream::pcount ()

Report the current length of the string associated with this ostrstream.

Method: char* ostrstream::str ()

A pointer to the string managed by this ostrstream. Implies `ostrstream::freeze()'.

Note that if you want the string to be nul-terminated, you must do that yourself (perhaps by writing ends to the stream).

Method: void ostrstream::freeze ([int n])

If n is nonzero (the default), declare that the string associated with this ostrstream is not to change dynamically; while frozen, it will not be reallocated if it needs more space, and it will not be deallocated when the ostrstream is destroyed. Use `freeze(1)' if you refer to the string as a pointer after creating it via ostrstream facilities.

`freeze(0)' cancels this declaration, allowing a dynamically allocated string to be freed when its ostrstream is destroyed.

If this ostrstream is already static--that is, if it was created to manage an existing statically allocated string---freeze is unnecessary, and has no effect.

Method: int ostrstream::frozen ()

Test whether freeze(1) is in effect for this string.

Method: strstreambuf* strstreambase::rdbuf ()

A pointer to the underlying strstreambuf.


Go to the first, previous, next, last section, table of contents.