std::basic_...buf::setbuf(3)
π std::basic_...buf::setbuf(3) π
okay bestie, welcome to this page from the C++ Standard Libary manual β yes, that's the spelling up there, and we're keeping it because it's iconic ππ
. This is the std::basic_stringbuf::setbuf page, and it's very much giving "protected virtual buffer behavior, read carefully."
πΈ NAME πΈ
std::basic_stringbuf::setbuf - std::basic_stringbuf::setbuf
β¨ Synopsis β¨
protected:
virtual std::basic_streambuf<CharT, Traits>* setbuf( char_type* s,
std::streamsize
n )
If s is a null pointer and n is zero, this function has no effect. literally nothing, no drama π.
Otherwise, bestie, the effect is implementation-defined: some implementations do nothing, while some implementations clear the std::string member currently used as the buffer and begin using the user-supplied character array of size n, whose first element is pointed to by s, as the buffer and the input/output character sequence. it's giving "your mileage may vary" energy. π¦
This function is protected virtual, so it may only be called through pubsetbuf() or from member functions of a user-defined class derived from std::basic_stringbuf. no random main-character calls from outside, iykyk. π
π Parameters π
sβ pointer to the firstCharTin the user-provided buffer or nullnβ the number ofCharTelements in the user-provided buffer or zero
π«Ά Return value π«Ά
this β that's the whole return value, bestie. periodt. π
π Notes π
ngl, the notes say the deprecated stream buffer std::strstreambuf or the boost.IOStreams device boost::basic_array may be used to implement I/O buffering over a user-provided char array in portable manner. deprecated, but still mentioned; respect the lore. π
π Example π
Test for the stringstream's setbuf functionality.
The page says // Run this code, and here's the code exactly:
#include <iostream>
#include <sstream>
int main()
{
std::ostringstream ss;
char c[1024] = {};
ss.rdbuf()->pubsetbuf(c, 1024);
ss << 3.14 << '\n';
std::cout << c << '\n';
}
π₯οΈ Output:
3.14 (on GNU g++/libstdc++ and SunPro C++/roguewave)
<nothing> (on MS Visual Studio 2010, SunPro C++/stlport4,
CLang++/libc++)
π See also π
pubsetbufinvokessetbuf()(public member function ofstd::basic_streambuf<CharT,Traits>)
mwah π β this page came from http://cppreference.com, dated 2024.06.10, and it's the std::basic_...buf::setbuf(3) page. periodt. πβ¨
π¦ 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