##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::strstream::freeze

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

[edit template]

void freeze(bool flag = true); |  |

If the stream is using a dynamically-allocated array for output, disables (flag == true) or enables (flag == false) automatic allocation/deallocation of the buffer. Effectively calls rdbuf()->pcount()

### [edit] Notes

After a call to str(), dynamic streams become frozen automatically. A call to freeze(false) is required before exiting the scope in which this strstream 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

flag | - | desired status

### [edit] Return value

(none)

### [edit] Example

Run this code

    #include <strstream>
    #include <iostream>

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

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

Possible output:

    The output stream contains "Test: 1.23"
    The output stream contains "Test: 1.23 More "

### [edit] See also

freeze | sets/clears the frozen state of the buffer (public member function of `std::strstreambuf`) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/strstream/freeze&oldid=63932"