std::basic_streambuf::setp(3)
π std::basic_streambuf::setp π
okay so bestie, this page is from the C++ Standard Libary manual, and it's all about std::basic_streambuf::setp. It's a protected member function situation, very behind-the-scenes, very main-character-internals energy π.
π NAME π
std::basic_streambuf::setp β std::basic_streambuf::setp, yes the name is literally the name, periodt π
.
β¨ Synopsis β¨
okay so it's protected:, and the signature is exactly this:
protected:
void setp( char_type* pbeg, char_type* pend );
It sets the values of the pointers that define the put area. Specifically, after the call:
pbase() == pbeg, pptr() == pbeg, epptr() == pend
Like, all three pointer vibes get updated in one go. Slay β¨.
π Parameters π
pbegβ a pointer to the new beginning of the put area. The start of the era, basically π«Ά.pendβ a pointer to the new end of the put area. The end of the era, the limit, the boundary π¦.
πΈ Return value πΈ
Literally (none), bestie. No return value, nothing, nada, empty-handed but cute π.
π¦ Example π¦
Run this code, it's giving custom stream buffer realness ππ:
// Run this code
#include <array>
#include <cstddef>
#include <iostream>
// Buffer for std::ostream implemented by std::array
template<std::size_t size, class CharT = char>
struct ArrayedStreamBuffer : std::basic_streambuf<CharT>
{
using Base = std::basic_streambuf<CharT>;
using char_type = typename Base::char_type;
ArrayedStreamBuffer()
{
// put area pointers to work with 'buffer'
Base::setp(buffer.data(), buffer.data() + size);
}
void print_buffer()
{
for (char_type i : buffer)
{
if (i == 0)
std::cout << "\\0";
else
std::cout << i;
std::cout << ' ';
}
std::cout << '\n';
}
private:
std::array<char_type, size> buffer{}; // value-initialize buffer
};
int main()
{
ArrayedStreamBuffer<10> streambuf;
std::ostream stream(&streambuf);
stream << "hello";
stream << ",";
streambuf.print_buffer();
}
β Output β
h e l l o , \0 \0 \0 \0
look at those little \0 besties filling the buffer, iconic π.
π See also π
setgβ repositions the beginning, next, and end pointers of the input sequence (protected member function).
mwah π β source/version: http://cppreference.com, date: 2024.06.10. bestie behavior only π§ββοΈβ¨
π¦ 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