std::basic_streambuf<CharT,Traits>::pbump
來自 cppreference.com
< 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
[編輯] 參閱
推進輸入序列中的下一個指標 (受保護成員函式) |