Namespaces
Variants

std::strstreambuf:: underflow

From cppreference.net
protected :
virtual int_type underflow ( ) ;
(in C++98 veraltet)
(in C++26 entfernt)

Liest das nächste Zeichen aus dem Get-Bereich des Puffers.

Wenn die Eingabesequenz eine Leseposition verfügbar hat ( gptr ( ) < egptr ( ) ), gibt ( unsigned char ) ( * gptr ( ) ) zurück.

Andernfalls, falls pptr() nicht null ist und pptr ( ) > egptr ( ) (es gibt einen Put-Bereich und dieser befindet sich nach dem Get-Bereich), erweitert das Ende des Get-Bereichs, um die kürzlich in den Put-Bereich geschriebenen Zeichen einzubeziehen, indem egptr() auf einen Wert zwischen gptr ( ) und pptr() erhöht wird, und gibt dann ( unsigned char ) ( * gptr ( ) ) zurück.

Andernfalls wird EOF zurückgegeben, um einen Fehler anzuzeigen.

Inhaltsverzeichnis

Parameter

(keine)

Rückgabewert

Das nächste Zeichen im Get-Bereich, ( unsigned char ) ( * gptr ( ) ) bei Erfolg, EOF bei Fehler.

Beispiel

#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';
}

Mögliche Ausgabe:

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

Siehe auch

[virtual]
liest Zeichen aus der zugehörigen Eingabesequenz in den Get-Bereich
(virtuelle geschützte Elementfunktion von std::basic_streambuf<CharT,Traits> )
[virtual]
gibt das nächste in der Eingabesequenz verfügbare Zeichen zurück
(virtuelle geschützte Elementfunktion von std::basic_stringbuf<CharT,Traits,Allocator> )
[virtual]
liest aus der zugehörigen Datei
(virtuelle geschützte Elementfunktion von std::basic_filebuf<CharT,Traits> )
liest ein Zeichen aus der Eingabesequenz ohne Fortschreiten der Sequenz
(öffentliche Elementfunktion von std::basic_streambuf<CharT,Traits> )
extrahiert Zeichen
(öffentliche Elementfunktion von std::basic_istream<CharT,Traits> )