std::strstr...strstreambuf(3)
π std::strstreambuf::strstreambuf π
okay bestie, welcome to the std::strstreambuf::strstreambuf page from the C++ Standard Libary manual β page name std::strstr...strstreambuf(3). yes the title is a lil cursed, but we move. π
πΈ NAME πΈ
std::strstreambuf::strstreambuf β std::strstreambuf::strstreambuf
β¨ Synopsis β¨
okay so the source page's columns are giving chaotic group-chat energy, but here are the overloads with their numbers and annotations kept intact, bestie:
- (1)
explicit strstreambuf( std::streamsize alsize = 0 );β (deprecated in C++98), (until C++11) - (1)
strstreambuf() : strstreambuf(0) {}β (since C++11), (removed in C++26) - (1)
explicit strstreambuf( std::streamsize alsize );β (deprecated in C++98), (removed in C++26) - (2)
strstreambuf( void* (*palloc)(std::size_t), void (*pfree)(void*) );β (deprecated in C++98), (removed in C++26) - (3)
strstreambuf( char* gnext, std::streamsize n, char* pbeg = 0 );β (deprecated in C++98), (removed in C++26) - (4)
strstreambuf( signed char* gnext, std::streamsize n, signed char* pbeg = 0 );β (deprecated in C++98), (removed in C++26) - (5)
strstreambuf( unsigned char* gnext, std::streamsize n, unsigned char* pbeg = 0 );β (deprecated in C++98), (removed in C++26) - (6)
strstreambuf( const char* gnext, std::streamsize n );β (deprecated in C++98), (removed in C++26) - (7)
strstreambuf( const signed char* gnext, std::streamsize n );β (deprecated in C++98), (removed in C++26) - (8)
strstreambuf( const unsigned char* gnext, std::streamsize n );β (deprecated in C++98), (removed in C++26)
π§ what each overload is actually doing π§
- 1) constructs a
std::strstreambufobject: initializes the base class by calling the default constructor ofstd::streambuf, initializes the buffer state to"dynamic"(the buffer will be allocated as needed), initializes allocated size to the providedalsize, initializes the allocation and the deallocation functions to null (will usenew[]anddelete[]). - 2) constructs a
std::strstreambufobject: initializes the base class by calling the default constructor ofstd::streambuf, initializes the buffer state to"dynamic"(the buffer will be allocated as needed), initializes allocated size to an unspecified value, initializes the allocation function topallocand the deallocation function topfree. - 3-5) constructs a
std::strstreambufobject in the following steps:- a) initializes the base class by calling the default constructor of
std::streambuf. - b) initializes the buffer state to
"constant"(the buffer is a user-provided fixed-size buffer). - c) determines the number of elements in the user-provided array as follows: if
nis greater than zero,nis used. Ifnis zero,std::strlen(gnext)is executed to determine the buffer size. Ifnis negative,INT_MAXis used. - d) configures the
std::basic_streambufpointers as follows: ifpbegis a null pointer, callssetg(gnext, gnext, gnext + N). Ifpbegis not a null pointer, executessetg(gnext, gnext, pbeg)andsetp(pbeg, pbeg + N), whereNis the number of elements in the array as determined earlier.
- a) initializes the base class by calling the default constructor of
- 6-8) same as
strstreambuf((char*)gnext, n), except the"constant"bit is set in the buffer state bitmask β output to this buffer is not allowed. π¨
π Parameters π
alsizeβ the initial size of the dynamically allocated bufferpallocβ pointer to user-provided allocation functionpfreeβ pointer to user-provided deallocation functiongnextβ pointer to the start of the get area in the user-provided arraypbegβ pointer to the start of the put area in the user-provided arraynβ the number of bytes in the get area (ifpbegis null) or in the put area (ifpbegis not null) of the user-provided array
π¦ Notes π¦
these constructors are typically called by the constructors of std::strstream.
π©Ή Defect reports π©Ή
the following behavior-changing defect reports were applied retroactively to previously published C++ standards:
P0935R0β applied to C++11. Behavior as published: default constructor wasexplicit. Correct behavior: madeimplicit.
π Example π
// Run this code
#include <iostream>
#include <strstream>
int main()
{
std::strstreambuf dyn; // dynamic
std::strstream dyn_s; // equivalent stream
dyn_s << 1.23 << std::ends;
std::cout << dyn_s.str() << '\n';
dyn_s.freeze(false);
char buf[10];
std::strstreambuf user(buf, 10, buf); // user-provided output buffer
std::ostrstream user_s(buf, 10); // equivalent stream
user_s << 1.23 << std::ends;
std::cout << buf << '\n';
std::strstreambuf lit("1 2 3", 5); // constant
std::istrstream lit_s("1 2 3"); // equivalent stream
int i, j, k;
lit_s >> i >> j >> k;
std::cout << i << ' ' << j << ' ' << k << '\n';
}
π€ Output π€
1.23
1.23
1 2 3
π₯ See also π₯
constructorβ constructs astrstreamobject, optionally allocating the buffer (public member function ofstd::strstream)
mwah π this page came from http://cppreference.com, dated 2024.06.10, and it's the std::strstr...strstreambuf(3) page. byeee π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms