首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_filebuf::underflow

protected: virtual int_type underflow()

?

?

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

行为类似于基类。std::basic_streambuf::underflow,除了要将关联字符序列%28(文件%29)中的数据读取到get区域外,首先将文件中的字节读入临时缓冲区%28,并根据需要分配到%29,然后使用std::codecvt::in对于要转换外部%28的输入区域设置,多字节%29表示形式转换为内部窗体,然后用于填充GET区域。如果区域设置%27 s,则可能跳过转换std::codecvt::always_noconv回报true...

参数

%280%29

返回值

Traits::to_int_type(*gptr())%28挂起序列%29的第一个字符(如果成功),或Traits::eof()万一失败。

二次

代码语言:javascript
复制
#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()) ;
}

二次

可能的产出:

二次

代码语言:javascript
复制
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

二次

另见

underflow virtual

reads characters from the associated input sequence to the get area (virtual protected member function of std::basic_streambuf)

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)

uflow virtual

reads from the associated file and advances the next pointer in the get area (virtual protected member function)

overflow virtual

writes characters to the associated file from the put area (virtual protected member function)

sgetc

reads one character from the input sequence without advancing the sequence (public member function of std::basic_streambuf)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com