std::basic_...f::underflow(3)
π std::basic_...f::underflow(3) π
okay so bestie, this page is from the C++ Standard Libary manual, and we're talking about std::basic_filebuf::underflow. it's a protected virtual member function and it is literally here to read more data into the input area. no cap, the vibe is βfill up the get areaβ π
πΈ NAME πΈ
std::basic_filebuf::underflow β std::basic_filebuf::underflow
(Yes, the NAME line is just the function name twice, it's giving self-titled main character energy π.)
β¨ Synopsis β¨
protected:
virtual int_type underflow()
Reads more data into the input area. π
It behaves like the base class std::basic_streambuf::underflow, except that to read the data from the associated character sequence (the file) into the get area, it first reads the bytes from the file into a temporary buffer (allocated as large as necessary), then uses std::codecvt::in of the imbued locale to convert the external (typically, multibyte) representation to the internal form which is then used to populate the get area. The conversion may be skipped if the locale's std::codecvt::always_noconv returns true. π¦
π Parameters π
- (none) β literally no parameters, bestie, it takes zero arguments π
π Return value π
Traits::to_int_type(*gptr()) (the first character of the pending sequence) in case of success, or Traits::eof() in case of failure. That's the whole mood: first pending char on a win, eof on a fail π
π Example π
// Run this code
#include <fstream>
#include <iostream>
struct mybuf : std::filebuf
{
int underflow()
{
std::cout << "Before underflow(): size of the get area is "
<< egptr()-eback() << " with "
<< egptr()-gptr() << " read positions available\n";
int rc = std::filebuf::underflow();
std::cout << "underflow() returns " << rc << ".\nAfter the call, "
<< "size of the get area is "
<< egptr()-eback() << " with "
<< egptr()-gptr() << " read positions available\n";
return rc;
}
};
int main()
{
mybuf buf;
buf.open("test.txt", std::ios_base::in);
std::istream stream(&buf);
while (stream.get()) ;
}
π₯ Possible output π₯
Before underflow(): size of the get area is 0 with 0 read positions available
underflow() returns 73.
After the call, size of the get area is 110 with 110 read positions available
Before underflow(): size of the get area is 110 with 0 read positions available
underflow() returns -1.
After the call, size of the get area is 0 with 0 read positions available
π¦ See also π¦
underflowβ reads characters from the associated input sequence to the get area[virtual](virtual protected member function ofstd::basic_streambuf<CharT,Traits>)underflowβ returns the next character available in the input sequence[virtual](virtual protected member function ofstd::basic_stringbuf<CharT,Traits,Allocator>)underflowβ reads a character from the input sequence without advancing the next[virtual]pointer (virtual protected member function ofstd::strstreambuf)uflowβ reads from the associated file and advances the next pointer in the get area[virtual](virtual protected member function)overflowβ writes characters to the associated file from the put area[virtual](virtual protected member function)sgetcβ reads one character from the input sequence without advancing the sequence (public member function ofstd::basic_streambuf<CharT,Traits>)
made with π by your Unix bestie β source/version: http://cppreference.com, date: 2024.06.10, page: std::basic_...f::underflow(3) π«Ά
π¦ 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