Apache C++ Standard Library Reference Guide

## basic_ostringstream

Library: Input/output

    basic_ostringstream  basic_ostream  basic_ios  ios_base

- Local Index
- Summary
- Synopsis
- Description
- Interface
- Member Types
- Nonmember Types
- Constructors
- Destructors
- Member Functions
- Example
- See Also
- Standards Conformance

### Local Index

#### Members

allocator_type basic_ostringstream() char_type | int_type ios_type off_type | pos_type rdbuf() str() | traits_type ~basic_ostringstream()

#### Non-Members

ostringstream | wostringstream |

### Summary

Class that supports writing objects of specializations of class template basic_string

### Synopsis

    #include <sstream>

    namespace std {
      template<class charT, class traits = char_traits<charT>,
               class Allocator = allocator<void> >
      class basic_ostringstream;
    }

### Description

The class template basic_ostringstream writes to an array in memory. It supports writing objects of class basic_string. It uses a basic_stringbuf object to control the associated storage. It inherits from basic_ostream, and therefore can use all the formatted and unformatted output functions.

### Interface

    namespace std {

      template<class charT, class traits = char_traits<charT>,
               class Allocator = allocator<charT> >
      class basic_ostringstream
      : public basic_ostream<charT, traits>
      {
       public:

        typedef traits                           traits_type;
        typedef charT                            char_type;
        typedef Allocator                        allocator_type;
        typedef typename traits_type::int_type   int_type;
        typedef typename traits_type::pos_type   pos_type;
        typedef typename traits_type::off_type   off_type;

        explicit
        basic_ostringstream(ios_base::openmode = ios_base::out);

        explicit
        basic_ostringstream(const basic_string<char_type,
                            traits_type, allocator_type>&,
                            ios_base::openmode = ios_base::out);

        virtual ~basic_ostringstream();

        basic_stringbuf<char_type, traits_type, allocator_type>*
        rdbuf() const;
        basic_string<char_type, traits_type, allocator_type>
        str() const;
        void
        str(const basic_string<char_type, traits_type,
                               allocator_type>& str);
      };
    }

### Member Types

    allocator_type

The type `allocator_type` is a synonym for the template parameter `Allocator`.

    char_type

The type `char_type` is a synonym for the template parameter `charT`.

    int_type

The type `int_type` is a synonym of type `traits::in_type`.

    ios_type

The type`ios_type` is an instantiation of class basic_ios on type `charT`.

    off_type

The type `off_type` is a synonym of type `traits::off_type`.

    pos_type

The type `pos_type` is a synonym of type `traits::pos_type`.

    traits_type

The type `traits_type` is a synonym for the template parameter `traits`.

### Nonmember Types

    ostringstream

The type `ostringstream` is a specialization of class basic_ostringstream on type `char`:

`typedef basic_ostringstream<char> ostringstream;`

    wostringstream

The type `wostringstream` is a specialization of class basic_ostringstream on type `wchar_t`:

`typedef basic_ostringstream<wchar_t> wostringstream;`

### Constructors

    explicit basic_ostringstream(ios_base::openmode which =
                                 ios_base::out);

Constructs an object of class basic_ostringstream, initializing the base class basic_ostream with the associated string buffer. The string buffer is initialized by calling the basic_stringbuf constructor:

`basic_stringbuf<charT,traits,Allocator>(which);`

    explicit basic_ostringstream(const basic_string<char_type,
                                traits_type, allocator_type>& str,
                                 ios_base::openmode which =
                                 ios_base::out);

Constructs an object of class basic_ostringstream, initializing the base class basic_ostream with the associated string buffer. The string buffer is initialized by calling the basic_stringbuf constructor:

`basic_stringbuf<char_type, traits_type,
allocator_type>(str, which)`;

### Destructors

    virtual ~basic_ostringstream();

Destroys an object of class basic_ostringstream.

### Member Functions

    basic_stringbuf<char_type, traits_type, allocator_type>*
    rdbuf() const;

Returns a pointer to the basic_stringbuf associated with the stream.

    basic_string<char_type, traits_type, allocator_type>
    str() const;

Returns `rdbuf()->str()`.

    void
    str(const basic_string<char_type, traits_type, allocator_type>& str);

Calls `rdbuf()->str (str)`.

### Example

See basic_stringstream, basic_istringstream and basic_stringbuf examples.

### See Also

char_traits, ios_base, basic_ios, basic_stringbuf, basic_string, basic_istringstream, basic_stringstream

### Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Section 27.7.3