命名空间
变体
操作

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,则可以跳过转换。

目录

[编辑] 参数

(无)

[编辑] 返回值

如果成功,返回 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

[编辑] 参阅

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