## ostrstream

    ostrstreambasic_ostreambasic_iosios_base

- Summary
- Data Type and Member Function Indexes
- Synopsis
- Description
- Interface
- Types
- Constructors
- Destructors
- Member Functions
- Example
- See Also
- Standards Conformance

### Summary

Writes to an array in memory.

### Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Data Types
char_type int_type off_type pos_type | traits

Member Functions
freeze() pcount() rdbuf() str()

### Synopsis

    #include <strstream>
    class ostrstream
    : public basic_ostream<char>

### Description

The class ostrstream writes to an array in memory. It uses a private strstreambuf object to control the associated array object. It inherits from basic_ostream<char> and therefore can use all the formatted and unformatted output functions.

This is a deprecated feature and might not be available in future versions.

### Interface

    class ostrstream
    : public basic_ostream<char> {

     public:

      typedef char_traits<char>             traits;

      typedef char                         char_type;
      typedef typename traits::int_type    int_type;
      typedef typename traits::pos_type    pos_type;
      typedef typename traits::off_type    off_type;

      ostrstream();
      ostrstream(char *s, int n,
                 ios_base::openmode = ios_base::out);

      virtual ~ostrstream();

      strstreambuf *rdbuf() const;
      void freeze(int freezefl = 1);
      char *str();
      int pcount() const;

    };

### Types

    char_type

The type `char_type` is a synonym of type `char`.

    int_type

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

    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

The type `traits` is a synonym of type `char_traits<char>`.

### Constructors

    ostrstream();

Constructs an object of class `ostrstream`, initializing the base class `basic_ostream<char>` with the associated `strstreambuf` object. The `strstreambuf` object is initialized by calling its default constructor `strstreambuf()`.

    ostrstream(char* s, int n, ios_base::openmode
               mode = ios_base::out);

Constructs an object of class `ostrstream`, initializing the base class `basic_ostream<char>` with the associated `strstreambuf` object. The `strstreambuf` object is initialized by calling one of two constructors:

- If `mode & app == 0`, it calls `strstreambuf(s,n,s)`

- Otherwise it calls `strstreambuf(s,n,s + ::strlen(s))`

### Destructors

    virtual ~ostrstream();

Destroys an object of class `ostrstream`.

### Member Functions

    void
    freeze(bool freezefl = 1);

If the mode is dynamic, alters the freeze status of the dynamic array object as follows:

- If `freezefl` is `false`, the function sets the freeze status to frozen.

- Otherwise, it clears the freeze status.

    int
    pcount() const;

Returns the size of the output sequence.

    strstreambuf*
    rdbuf() const;

Returns a pointer to the private `strstreambuf` object associated with the stream.

    char*
    str();

Returns a pointer to the underlying array object, which may be null.

### Example

See strstream, istrstream and strstreambuf examples.

### See Also

char_traits(3C++), ios_base(3C++), basic_ios(3C++), strstreambuf(3C++), istrstream(3C++), strstream(3C++)

Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Annex D Compatibility features Section D.6.3

### Standards Conformance

ANSI X3J16/ISO WG21 Joint C++ Committee

Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998