std::strstreambuf:: underflow
|
protected
:
virtual int_type underflow ( ) ; |
(obsolète en C++98)
(supprimé en C++26) |
|
Lit le caractère suivant de la zone de lecture du tampon.
Si la séquence d'entrée a une position de lecture disponible ( gptr ( ) < egptr ( ) ), retourne ( unsigned char ) ( * gptr ( ) ) .
Sinon, si pptr() n'est pas nul et pptr ( ) > egptr ( ) (il existe une zone de mise en mémoire tampon et elle est située après la zone de lecture), étend la fin de la zone de lecture pour inclure les caractères récemment écrits dans la zone de mise en mémoire tampon en incrémentant egptr() à une valeur entre gptr ( ) et pptr() , puis retourne ( unsigned char ) ( * gptr ( ) ) .
Sinon, retourne EOF pour indiquer un échec.
Table des matières |
Paramètres
(aucun)
Valeur de retour
Le prochain caractère dans la zone de lecture, ( unsigned char ) ( * gptr ( ) ) en cas de succès, EOF en cas d'échec.
Exemple
#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'; }
Sortie possible :
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
Voir aussi
|
[virtual]
|
lit les caractères de la séquence d'entrée associée vers la zone de récupération
(fonction membre protégée virtuelle de
std::basic_streambuf<CharT,Traits>
)
|
|
[virtual]
|
retourne le prochain caractère disponible dans la séquence d'entrée
(fonction membre protégée virtuelle de
std::basic_stringbuf<CharT,Traits,Allocator>
)
|
|
[virtual]
|
lit depuis le fichier associé
(fonction membre protégée virtuelle de
std::basic_filebuf<CharT,Traits>
)
|
|
lit un caractère de la séquence d'entrée sans avancer la séquence
(fonction membre publique de
std::basic_streambuf<CharT,Traits>
)
|
|
|
extrait des caractères
(fonction membre publique de
std::basic_istream<CharT,Traits>
)
|