Namespaces
Variants

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

From cppreference.net
protected :
virtual int_type underflow ( )

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

行为类似于基类 std :: basic_streambuf :: underflow ,不同之处在于:为了将关联字符序列(文件)中的数据读入获取区域,首先将字节从文件读入临时缓冲区(按需分配足够大的空间),然后使用注入区域的 std :: codecvt :: in 将外部(通常为多字节)表示形式转换为内部形式,随后用其填充获取区域。如果区域的 std :: codecvt :: always_noconv 返回 true ,则可以跳过转换过程。

目录

参数

(无)

返回值

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

示例

#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

参见

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