命名空间
变体
操作

std::basic_filebuf<CharT,Traits>::underflow

来自 cppreference.cn
< cpp‎ | io‎ | basic filebuf
 
 
 
 
protected:
virtual int_type underflow()

将更多数据读入输入区域。

行为类似基类 std::basic_streambuf::underflow,除了要从关联的字符序列(文件)中读取数据到获取区域,首先从文件中读取字节到临时缓冲区(分配足够大的空间),然后使用 std::codecvt::in 嵌入区域设置的 来转换外部(通常是多字节)表示形式为内部形式,然后用于填充获取区域。如果区域设置的 std::codecvt::always_noconv 返回 true,则可以跳过转换。

目录

[edit] 参数

(无)

[edit] 返回值

成功时返回 Traits::to_int_type(*gptr()) (待处理序列的第一个字符),失败时返回 Traits::eof()

[edit] 示例

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

可能的输出

Before underflow(): size of the get area is 0 with 0 read positions available
underflow() returns 73.
After the call, size of the get area is 110 with 110 read positions available
Before underflow(): size of the get area is 110 with 0 read positions available
underflow() returns -1.
After the call, size of the get area is 0 with 0 read positions available

[edit] 参见

[虚函数]
从关联的输入序列读取字符到获取区域
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [edit]
[虚函数]
返回输入序列中下一个可用的字符
(std::basic_stringbuf<CharT,Traits,Allocator> 的虚保护成员函数) [edit]
[虚函数]
从输入序列中读取一个字符,但不推进下一个指针
(std::strstreambuf 的虚保护成员函数) [edit]
[虚函数]
从关联的文件中读取并推进获取区域中的下一个指针
(虚保护成员函数) [edit]
[虚函数]
将字符从放置区域写入到关联的文件
(虚保护成员函数) [edit]
从输入序列中读取一个字符,但不推进序列
(std::basic_streambuf<CharT,Traits> 的公共成员函数) [edit]