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

来自cppreference.com
< cpp‎ | io‎ | basic filebuf
 
 
 
 
protected:
virtual std::streamsize showmanyc()
(optional)

若实现,则返回从文件留待读取的字符数。

目录

[编辑] 返回值

可从文件读取的字符数,或若抵达文件尾则为 -1

[编辑] 注解

此函数为可选。若不实现,则此函数返回 0(因为基类版本 std::basic_streambuf::showmanyc 得到调用)。

无论是否实现,此函数通常为 std::basic_streambuf::in_avail 在获取区为空时所调用。

此函数的名���表示“流:多少字符?”,故它读作“S how many C”,而不是“show many C”。

[编辑] 示例

查看是否为 std::filebuf 实现 showmanyc() 的实现测试

#include <fstream>
#include <iostream>
 
struct mybuf : std::filebuf
{
    using std::filebuf::showmanyc;
};
 
int main()
{
    mybuf fin;
    fin.open("main.cpp", std::ios_base::in);
    std::cout << "showmanyc() returns " << fin.showmanyc() << '\n';
}

可能的输出:

showmanyc() returns 254

[编辑] 参阅

获得获取区中立即可用的字符数
(std::basic_streambuf<CharT,Traits> 的公开成员函数) [编辑]
提取已经可用的字符区块
(std::basic_istream<CharT,Traits> 的公开成员函数) [编辑]