std::strstr...::underflow(3)
Okay bestie, welcome to std::strstr...::underflow(3) from the C++ Standard Libary (yes, thatβs the manual name, and weβre rolling with it π
). This is the std::strstreambuf::underflow page, and itβs giving vintage-buffer energy fr fr.
πΈ NAME πΈ
std::strstreambuf::underflow β std::strstreambuf::underflow (the name is literally the name again, and honestly? iconic).
β¨ Synopsis β¨
protected: (deprecated in C++98)
virtual int_type underflow(); (removed in C++26)
Big yikes: deprecated in C++98 and removed in C++26. But the vibe of the function is still this: it reads the next character from the get area of the buffer.
Okay so, if the input sequence has a read position available (gptr() < egptr()), it returns (unsigned char)(*gptr()). Slay.
Otherwise, if pptr() is not null and pptr() > egptr() β meaning there is a put area and it is located after the get area β it extends the end of the get area to include the characters that were recently written into the put area. How? By incrementing egptr() to some value between gptr() and pptr(), and then it returns (unsigned char)(*gptr()). No cap.
Otherwise, it returns EOF to indicate failure. Periodt. π
π Parameters π
- (none) β literally none, bestie. Zero. Nada. π«Ά
π Return value π
The next character in the get area, (unsigned char)(*gptr()), on success. EOF on failure. Thatβs the whole vibe check.
π₯ Example π₯
Hereβs the code, bestie β exact and unbothered:
// Run this code
#include <iostream>
#include <strstream>
struct mybuf : std::strstreambuf
{
int_type overflow(int_type c)
{
std::cout << "Before overflow(): size of the get area is " <<
egptr()-eback()
<< " size of the put area is " << epptr()-pbase() <<
'\n';
int_type rc = std::strstreambuf::overflow(c);
std::cout << "After overflow(): size of the get area is " <<
egptr()-eback()
<< " size of the put area is " << epptr()-pbase() <<
'\n';
return rc;
}
int_type underflow()
{
std::cout << "Before underflow(): size of the get area is " <<
egptr()-eback()
<< " size of the put area is " << epptr()-pbase() <<
'\n';
int_type ch = std::strstreambuf::underflow();
std::cout << "After underflow(): size of the get area is " <<
egptr()-eback()
<< " size of the put area is " << epptr()-pbase() <<
'\n';
if (ch == EOF)
std::cout << "underflow() returns EOF\n";
else
std::cout << "underflow() returns '" << char(ch) << "'\n";
return ch;
}
};
int main()
{
mybuf sbuf; // read-write dynamic strstreambuf
std::iostream stream(&sbuf);
int n;
stream >> n;
stream.clear();
stream << "123";
stream >> n;
std::cout << n << '\n';
}
π Possible output: π
Before underflow(): size of the get area is 0 size of the put area is 0
After underflow(): size of the get area is 0 size of the put area is 0
underflow() returns EOF
Before overflow(): size of the get area is 0 size of the put area is 0
After overflow(): size of the get area is 0 size of the put area is 32
Before underflow(): size of the get area is 0 size of the put area is
32
After underflow(): size of the get area is 3 size of the put area is 32
underflow() returns '1'
Before underflow(): size of the get area is 3 size of the put area is
32
After underflow(): size of the get area is 3 size of the put area is 32
underflow() returns EOF
123
π See also π
underflowreads characters from the associated input sequence to the get area[virtual](virtual protected member function ofstd::basic_streambuf<CharT,Traits>)underflowreturns the next character available in the input sequence[virtual](virtual protected member function ofstd::basic_stringbuf<CharT,Traits,Allocator>)underflowreads from the associated file[virtual](virtual protected member function ofstd::basic_filebuf<CharT,Traits>)sgetcreads one character from the input sequence without advancing the sequence (public member function ofstd::basic_streambuf<CharT,Traits>)getextracts characters (public member function ofstd::basic_istream<CharT,Traits>)
π source/version: http://cppreference.com β’ date: 2024.06.10 π
π¦ 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