Jeffrey
Jeffrey

Reputation: 4506

How the functions overflow and underflow of basic_streambuf wok

I'm reading the C++ 11 standard. The sections 27.6.3.4.3/7 and 27.6.3.4.5/3 describe the functions "int_type underflow();" and "int_type overflow(int_type c = traits::eof());". There is no example to explain how they work. Can somebody help to explain the functions with the example?

Upvotes: 0

Views: 813

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490178

The basic idea is pretty simple. underflow is used for input streams. When there's no data left in the input buffer, underflow is called to read data from the actual source (e.g., file or socket) to at least partially refill the buffer.

overflow is pretty much the opposite -- when a buffer is full, overflow is called to write the data out to the associated file or socket, or whatever. It's also called to flush the buffer just before an output stream is destroyed.

Upvotes: 4

Related Questions