命名空间
变体
操作

std::basic_streambuf<CharT,Traits>::pbump

来自 cppreference.cn
< cpp‎ | io‎ | basic streambuf
 
 
 
 
protected:
void pbump( int count );

通过 count 个字符来重定位放置指针pptr()),其中 count 可以是正数或负数。不进行检查以防止指针移动到放置区 [pbase()epptr()) 之外。

如果指针前移,然后调用 overflow() 将放置区刷新到关联的字符序列,效果是会额外输出 count 个具有未定义值的字符。

目录

[编辑] 参数

count - 要加到放置指针上的数值

[编辑] 返回值

(无)

[编辑] 注意

因为此函数接受一个 int,所以它无法操作大于 std::numeric_limits<int>::max() 个字符的缓冲区 (LWG 问题 255)。

[编辑] 示例

#include <fstream>
#include <iostream>
#include <string>
 
struct showput_streambuf : std::filebuf
{
    using std::filebuf::pbump; // expose protected
    std::string showput() const
    {
        return std::string(pbase(), pptr());
    }
};
 
int main()
{
    showput_streambuf mybuf;
    mybuf.open("test.txt", std::ios_base::out);
    std::ostream str(&mybuf);
    str << "This is a test" << std::flush << "1234";
    std::cout << "The put area contains: " << mybuf.showput() << '\n';
    mybuf.pbump(10);
    std::cout << "after pbump(10), it contains " << mybuf.showput() << '\n';
}

输出

The put area contains: 1234
after pbump(10), it contains 1234 is a test

[编辑] 参阅

推进输入序列中的下一个指针
(受保护成员函数) [编辑]