std::basic_streambuf<CharT,Traits>::pbump
来自 cppreference.cn
< cpp | io | basic streambuf
protected: void pbump( int count ); |
||
将放置指针 (pptr()) 重新定位 count 个字符,其中 count 可以是正数或负数。 不会检查指针是否移动到放置区域 [
pbase(),
epptr())
之外。
如果指针被提前,然后调用 overflow() 以将放置区域刷新到关联的字符序列,则效果是输出额外的 count 个具有未定义值的字符。
目录 |
[编辑] 参数
count | - | 要添加到放置指针的数字 |
[编辑] 返回值
(无)
[编辑] 注释
由于此函数接受 int,因此它无法操作大于 std::numeric_limits<int>::max() 个字符的缓冲区 (LWG issue 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
[编辑] 参见
在输入序列中前进下一个指针 (受保护的成员函数) |