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::ostrstream::str(3) C++ Standard Libary std::ostrstream::str(3)

std::ostrstream::str - std::ostrstream::str


char* str();


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


(none)


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


Before a call to str() that uses the result as a C string, the stream buffer must be
null-terminated. Regular output such as with stream << 1.2 does not store a null
terminator, it must be appended explicitly, typically with the manipulator
std::ends.


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, which may
leave the buffer not null-terminated.

// Run this code


#include <strstream>
#include <iostream>


int main()
{
std::ostrstream dyn; // dynamically-allocated output buffer
dyn << "Test: " << 1.23; // not adding std::ends to demonstrate append behavior
std::cout << "The output stream holds \"";
std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
// the stream is now frozen due to str()
dyn << " More text" << std::ends;
std::cout << "The output stream holds \"";
std::cout.write(dyn.str(), dyn.pcount()) << "\"\n";
dyn.freeze(false);
}


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


str marks the buffer frozen and returns the beginning pointer of the input sequence
(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.