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
strstreambufobject and passing the address of the string buffer to the base-class constructor forostream.-
ostrstream(char* str, int n, ios_base::openmodemode=ios_base::out) Initializes a string stream with
stras the initial string contents by constructing an internalstrstreambufobject and passing the address of the buffer to the base-class constructor forostream. If theios_base::appbit is set inmode, the buffer is constructed like this:strstreambuf(str, n, str + std::strlen(str));
If the
ios_base::appbit is clear in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access