##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::ostrstream::str

From cppreference.com
< cpp‎ | io‎ | ostrstream

[edit template]

char* str(); |  |

Returns the pointer to the beginning of the buffer, after freezing it. Effectively calls rdbuf()->str()

### Notes

After a call to str(), dynamic streams become frozen. A call to freeze(false) is required before exiting the scope in which this ostrstream object was created. otherwise the destructor will leak memory. Also, additional output to a frozen stream may be truncated once it reaches the end of the allocated buffer.

### [edit] Parameters

(none)

### [edit] Return value

Pointer to the beginning of the buffer in the associated std::strsteambuf or NULL if no buffer is available.

### [edit] Example

Run this code

    #include <strstream>
    #include <iostream>

    int main()
    {
        std::ostrstream dyn; // dynamically-allocated output buffer
        dyn << "Test: " << 1.23;
        std::cout << "The output stream holds \"" << dyn.str() << "\"\n";

        dyn << "Test: " << 1.23;
        std::cout << "The output stream holds \"" << dyn.str() << "\"\n";
        // the stream is now frozen due to str()
        dyn << " More text";
        std::cout << "The output stream holds \"" << dyn.str() << "\"\n";
        dyn.freeze(false);
    }

Possible output:

    The stream holds "Test: 1.23"
    The stream holds "Test: 1.23 More "

### See also

str | marks the buffer frozen and returns the beginning pointer of the input sequence (public member function of `std::strstreambuf`) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/ostrstream/str&oldid=63933"