std::basic_streambuf::underflow
来自cppreference.com
< cpp | io | basic streambuf
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
int_type underflow(); |
||
确保一个的至少一个的字符是可在输入区中的更新的指针的输入区(如果需要的话)。返回值的,成功或失败的traits::eof()上的字符.
原文:
Ensures that at least one character is available in the input area by updating the pointers to the input area (if needed). Returns the value of that character on success or traits::eof() on failure.
该函数可能更新
gptr
,egptr
和eback
定义新加载的数据(如有的话)的位置的指针。发生故障时,该功能可确保无论是gptr() == nullptr或gptr() == egptr.原文:
The function may update
gptr
, egptr
and eback
pointers to define the location of newly loaded data (if any). On failure, the function ensures that either gptr() == nullptr or gptr() == egptr.基类版本的函数什么也不做。派生类可以重载这个函数来取回区耗尽的情况下,允许更新.
原文:
The base class version of the function does nothing. The derived classes may override this function to allow updates to the get area in the case of exhaustion.
目录 |
[编辑] 参数
(无)
[编辑] 返回值
的字符值所指向的“指针”后,成功的呼叫,或以其他方式traits::eof().
原文:
The value of the character pointed to by the get pointer after the call on success, or traits::eof() otherwise.
的函数调用基类版本traits::eof().
原文:
The base class version of the function calls traits::eof().
[编辑] 请注意
公共职能std::streambuf调用这个函数,只有当gptr() == nullptr或gptr() >= egptr().
原文:
The public functions of std::streambuf call this function only if gptr() == nullptr or 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
[编辑] 另请参阅
[虚]</div></div>
|
相关的输入序列读取字符的get区和进步的下一个指针 原文: reads characters from the associated input sequence to the get area and advances the next pointer (虚拟保护成员函数) |
[虚]</div></div>
|
相关的输出序列中写入字符认沽区域 原文: writes characters to the associated output sequence from the put area (虚拟保护成员函数) |