basic_ostringstream class template — Base class for output string streams
template <class charT, class traits = char_traits<charT>, class Alloc = allocator<charT> > class basic_ostringstream: public basic_ostream<charT,traits> { public: typedef charT char_type; typedef typename traits::int_type int_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef traits traits_type; explicit basic_ostringstream(ios_base::openmode which = ios_base::out); explicit basic_ostringstream(const basic_string<charT,traits,Alloc>& str, ios_base::openmode which = ios_base::out); basic_stringbuf<charT,traits,Alloc>* rdbuf( ) const; basic_string<charT,traits,Alloc> str( ) const; void str(const basic_string<charT,traits,Alloc>& s); };
The basic_ostringstream
class template is the base class for output string streams.
Typically, you would construct an ostringstream
with no string and let the
string stream allocate the string as you write to the stream. You
would then call the str
member
function to read the resulting string.
The following are the methods of basic_ostringstream
:
explicit
basic_ostringstream
(ios_base::openmode
which
=
ios_base::out)
Initializes an empty output string stream by
constructing an internal basic_stringbuf
object, passing
which
|
ios_base::out
to that object's
constructor, and passing the address of the string buffer to
the base-class constructor for basic_ostream
.
explicit
basic_ostringstream
(const
basic_string<charT,traits,Alloc>&
str, ios_base::openmode
which
=
ios_base::out)
Initializes a string stream with str
as the initial string contents
by constructing an internal basic_stringbuf
object, passing
str
and which
|
ios_base::out
to that object's
constructor, and passing the address of the string buffer to
the base-class constructor for basic_ostream
.
basic_stringbuf<charT,traits,Alloc>*
rdbuf
( )
const
Returns a pointer to the internal basic_stringbuf
object.
basic_string<charT,traits,Alloc>
str
( )
const
Returns the buffer contents as a string, that is,
rdbuf( )->str( )
.
void
str
(const
basic_string<charT,traits,Alloc>&
s)
Calls rdbuf(
)->str(s)
to set the buffer contents.
basic_stringstream class
template, ostringstream
class, wostringstream
class, basic_ofstream
in
<fstream>
, basic_ostream
in <ostream>