在线文档教程
C++
输入/输出 | Input/output

std::strstreambuf::setbuf

std::strflow buf::setbuf

protected: virtual streambuf* setbuf(char* s, std::streamsize n

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

否则,效果就是实现定义的:一些实现什么也不做,而一些实现释放用作缓冲区的动态成员数组,并开始使用用户提供的大小的字符数组。n,其第一个元素被s...

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

参数

s-pointer to the first byte in the user-provided buffer
n-the number of bytes in the user-provided buffer

返回值

this...

实现测试,以检查在Sun Studio%29获得的动态strstream%28输出中是否支持setbuf%28%29。

二次

#include <strstream> #include <iostream> int main() { char a[100] = {}; std::strstream str; str.rdbuf()->pubsetbuf(a, sizeof a str << "Test string" << std::ends; std::cout << "user-provided buffer holds '" << a << "'\n"; }

二次

可能的产出:

二次

user-provided buffer holds 'Test string'

二次

另见

pubsetbufinvokes setbuf() (public member function of std::basic_streambuf)
setbuf virtualreplaces the buffer with user-defined array, if permitted (virtual protected member function of std::basic_streambuf)
setbuf virtualattempts to replace the controlled character sequence with an array (virtual protected member function of std::basic_stringbuf)
setbuf virtualprovides user-supplied buffer or turns this filebuf unbuffered (virtual protected member function of std::basic_filebuf)

© cppreference.com

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

http://en.cppreference.com/w/cpp/io/strStrebuf/setbuf