std::basic_streambuf::pubsetbuf
性病:基本[医]Streambuf::pubsetbuf,std::basic[医]流f::setbuf
basic_streambuf | (1) | |
---|---|---|
protected: virtual basic_streambuf<CharT, Traits>* setbuf( char_type* s, std::streamsize n ) | (2) | |
1%29次电话setbuf(s, n)
最派生的类
2%29此函数的基类版本没有任何影响。派生类可以重写此函数,以允许用用户提供的数组删除或替换受控字符序列%28(缓冲区%29),或用于任何其他特定于实现的目的。
参数
s | - | pointer to the first byte in the user-provided buffer |
---|---|---|
n | - | the number of bytes in the user-provided buffer |
返回值
1%29setbuf(s, n)
2%29this
例
提供10K的阅读缓冲区。在Linux上,可以使用strace实用程序来观察实际读取的字节数。
二次
#include <fstream>
#include <iostream>
#include <string>
int main()
{
int cnt = 0;
std::ifstream file;
char buf[10241];
file.rdbuf()->pubsetbuf(buf, sizeof buf
file.open("/usr/share/dict/words"
for (std::string line; getline(file, line) {
cnt++;
}
std::cout << cnt << '\n';
}
二次
另见
setbuf virtual | attempts to replace the controlled character sequence with an array (virtual protected member function of std::basic_stringbuf) |
---|---|
setbuf virtual | provides user-supplied buffer or turns this filebuf unbuffered (virtual protected member function of std::basic_filebuf) |
setbuf virtual | attempts to replace the controlled character sequence with an array (virtual protected member function of std::strstreambuf) |
setbuf | sets the buffer for a file stream (function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cppreference.com/w/cpp/io/basic[医]Streambuf/pubsetbuf