std::basic_filebuf::underflow














































std::basic_filebuf::underflow



underflow()


DESCRIPTION:
It is a protected virtual member function of
basic_filebuf template which is part of
<
fstream>
library. 
It returns the character at the current input position, without advancing the input position pointer.

If the input sequence has a read position available, returns the contents of this position. Otherwise fills up the buffer by reading characters from the associated file, and if it succeeds, returns the contents of the new current position.

Its prototype is:

int_type underflow();


------------------------------------------------------------------------

PARAMETERS: none

------------------------------------------------------------------------

RETURN VALUE:
The character at the current position of the controlled input sequence, converted to a value of type int.

If there are no more characters to read from the controlled input sequence, it returns the end-of-file value (EOF) i.e. traits::eof().

------------------------------------------------------------------------

EXAMPLE:

#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()) ;
}


CONTENT IN FILE:


C++ is a general-purpose programming language
created by Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significantly over time, and modern C++ now has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.



 OUTPUT:



Before underflow(): size of the get area is 0 with 0 read positions available

underflow() returns 67.

After the call, size of the get area is 327 with 327 read positions available

Before underflow(): size of the get area is 327 with 0 read positions available

underflow() returns -1.

After the call, size of
the get area is 0 with 0 read positions available


Comments