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 forostream
.-
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 internalstrstreambuf
object and passing the address of the buffer to the base-class constructor forostream
. If theios_base::app
bit is set inmode
, 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 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.