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

std::strstreambuf::str - std::strstreambuf::str


char* str() const;


Calls freeze(), then returns a copy of start pointer of the get area,
std::streambuf::eback().


The start of the get area, for all writeable std::strstreambuf objects constructed
through the interface provided by std::strstream, is also the start of the put area.


(none)


A copy of eback(), which may be a null pointer.


This function is typically called through the std::strstream interface.


The call to freeze() guarantees that the returned pointer remains valid until the
next explicit call to freeze(false): otherwise (on a dynamic buffer) any output
operation could trigger buffer reallocation which would invalidate the pointer. It
also causes a memory leak in the destructor of std::strstreambuf, unless
freeze(false) is called before the buffer (or, more commonly, the std::strstream
that manages it) is destroyed.

// Run this code


#include <strstream>
#include <iostream>


int main()
{
std::strstream dyn; // dynamically-allocated read/write buffer
dyn << "Test: " << 1.23 << std::ends;
std::strstreambuf* buf = dyn.rdbuf();
std::cout << "R/W buffer holds \"" << buf->str() // or dyn.str()
<< "\"\n";
dyn.freeze(false); // after calling .str() on a dynamic strstream


char arr[10];
std::ostrstream user(arr, 10); // fixed-size write-only buffer
buf = user.rdbuf();
user << 1.23 << std::ends;
std::cout << "Write-only buffer holds \"" << buf->str() // or user.str()
<< "\"\n";


std::istrstream lit("1 2 3"); // fixed-size read-only buffer
buf = lit.rdbuf();
std::cout << "Read-only buffer holds \"" << buf->str() // or lit.str()
<< "\"\n";
}


R/W buffer holds "Test: 1.23"
Write-only buffer holds "1.23"
Read-only buffer holds "1 2 31 2 3"


str accesses the output buffer
(public member function of std::strstream)
str accesses the output buffer
(public member function of std::ostrstream)
str accesses the output buffer
(public member function of std::istrstream)

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.