首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_streambuf::pubsetbuf

basic_streambuf<CharT, Traits>* pubsetbuf( char_type* s, std::streamsize n )

(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实用程序来观察实际读取的字节数。

二次

代码语言:javascript
复制
#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)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com