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

std::basic_stringbuf::setbuf

protected: virtual std::basic_streambuf<CharT, Traits>* setbuf( char_type* s, std::streamsize n )

?

?

如果s为空指针,并且n为零,此函数不起任何作用。

否则,效果就是实现定义的:一些实现什么也不做,而一些实现清除std::string成员当前用作缓冲区,并开始使用用户提供的大小字符数组。n,其第一个元素被s,作为缓冲区和输入/输出字符序列。

此函数是受保护的虚拟函数,只能通过pubsetbuf()派生的用户定义类的成员函数。std::basic_stringbuf...

参数

s

-

pointer to the first byte in the user-provided buffer or null

n

-

the number of bytes in the user-provided buffer or zero

返回值

this...

注记

不推荐的流缓冲区std::strstreambuf或者提振。IOStreams装置boost::basic_array可用于以可移植方式实现对用户提供的char数组的I/O缓冲。

测试字符串流%27s setbuf功能。

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
 
int main()
{
    std::ostringstream ss;
    char c[1024] = {};
    ss.rdbuf()->pubsetbuf(c, 1024);
    ss << 3.14 << '\n';
    std::cout << c << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
3.14 (on GNU g++/libstdc++ and SunPro C++/roguewave)
<nothing> (on MS Visual Studio 2010, SunPro C++/stlport4, CLang++/libc++)

二次

另见

pubsetbuf

invokes setbuf() (public member function of std::basic_streambuf)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com