GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::strstream::freeze(3) C++ Standard Libary std::strstream::freeze(3)

std::strstream::freeze - std::strstream::freeze


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()->freeze(flag)


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.


flag - desired status


(none)

// Run this code


#include <strstream>
#include <iostream>


int main()
{
std::strstream dyn; // dynamically-allocated output buffer
dyn << "Test: " << 1.23; // note: no std::ends to demonstrate appending
std::cout << "The output stream contains \"";
std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
// the stream is now frozen due to str()
dyn << " More text"; // output to a frozen stream may be truncated
std::cout << "The output stream contains \"";
std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
dyn.freeze(false); // freeze(false) must be called or the destructor will leak


std::strstream dyn2; // dynamically-allocated output buffer
dyn2 << "Test: " << 1.23; // note: no std::ends
std::cout << "The output stream contains \"";
std::cout.write(dyn2.str(), dyn2.pcount()) << "\"\n";
dyn2.freeze(false); // unfreeze the stream after str()
dyn2 << " More text" << std::ends; // output will not be truncated (buffer grows)
std::cout << "The output stream contains \"" << dyn2.str() << "\"\n";
dyn2.freeze(false); // freeze(false) must be called or the destructor will leak
}


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


freeze sets/clears the frozen state of the buffer
(public member function of std::strstreambuf)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.