std::basic_streambuf::underflow
性病:基本[医]流注::地下水流
virtual int_type underflow( | | |
---|
确保输入区域中至少有一个字符可用,方法是更新指向输入区域%28的指针(如果需要的话)%29,并从输入序列%28(如果适用的话)读取更多的数据。返回转换为int_type
带着Traits::to_int_type(c)
%29%关于成功或Traits::eof()
在失败的时候。
该功能可能更新gptr
,,,egptr
和eback
指针定义新加载的数据%28(如果有%29)的位置。如果失败,该函数将确保gptr() == nullptr
或gptr() == 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 virtual | reads characters from the associated input sequence to the get area and advances the next pointer (virtual protected member function) |
---|---|
overflow virtual | writes characters to the associated output sequence from the put area (virtual protected member function) |
underflow virtual | reads from the associated file (virtual protected member function of std::basic_filebuf) |
underflow virtual | returns the next character available in the input sequence (virtual protected member function of std::basic_stringbuf) |
underflow virtual | reads a character from the input sequence without advancing the next pointer (virtual protected member function of std::strstreambuf) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。