名稱空間
變體
操作

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

來自 cppreference.com
< 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> 的公有成員函式) [編輯]