在线文档教程
C++
输入/输出 | Input/output

std::basic_streambuf::underflow

性病:基本[医]流注::地下水流

virtual int_type underflow(

确保输入区域中至少有一个字符可用,方法是更新指向输入区域%28的指针(如果需要的话)%29,并从输入序列%28(如果适用的话)读取更多的数据。返回转换为int_type带着Traits::to_int_type(c)%29%关于成功或Traits::eof()在失败的时候。

该功能可能更新gptr,,,egptreback指针定义新加载的数据%28(如果有%29)的位置。如果失败,该函数将确保gptr() == nullptrgptr() == egptr...

函数的基类版本什么也不做。派生类可以重写此函数,以便在耗尽时允许对GET区域进行更新。

参数

%280%29

返回值

对象所指向的字符的值。获取指针在呼吁成功之后,或Traits::eof()否则。

函数的基类版本返回traits::eof()...

公共职能std::streambuf只在下列情况下才调用此函数gptr() == nullptr或gptr() >= egptr()...

二次

#include <iostream> #include <sstream> class null_filter_buf : public std::streambuf { std::streambuf* src; char ch; // single-byte buffer protected: int underflow() { while( (ch= src->sbumpc()) == '\0') ; // skip zeroes setg(&ch, &ch, &ch+1 // make one read position available return ch; // may return EOF } public: null_filter_buf(std::streambuf* buf) : src(buf) { setg(&ch, &ch+1, &ch+1 // buffer is initially full } }; void filtered_read(std::istream& in) { std::streambuf* orig = in.rdbuf( null_filter_buf buf(orig in.rdbuf(&buf for(char c; in.get(c ) std::cout << c; in.rdbuf(orig } int main() { char a[] = "This i\0s \0an e\0\0\0xample"; std::istringstream in(std::string(std::begin(a), std::end(a)) filtered_read(in }

二次

产出:

二次

This is an example

二次

另见

uflow virtualreads characters from the associated input sequence to the get area and advances the next pointer (virtual protected member function)
overflow virtualwrites characters to the associated output sequence from the put area (virtual protected member function)
underflow virtualreads from the associated file (virtual protected member function of std::basic_filebuf)
underflow virtualreturns the next character available in the input sequence (virtual protected member function of std::basic_stringbuf)
underflow virtualreads a character from the input sequence without advancing the next pointer (virtual protected member function of std::strstreambuf)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/basic[医]流道/底流