std::basic_stringbuf::setbuf
来自cppreference.com
< cpp | io | basic stringbuf
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
protected: virtual std::basic_streambuf<CharT, Traits>* setbuf( char_type* s, std::streamsize n ) |
||
s
是一个空指针,n
是零,这个功能有没有影响.....原文:
If
s
is a null pointer and n
is zero, this function has no effect.否则,其效果是实现定义的:一些实现什么也不做,而另一些实现清除std::string成员目前作为缓冲,并开始使用用户提供的字符数组的大小
n
,他的第一个元素所指向的s
,为缓冲器和输入/输出的字符序列.原文:
Otherwise, the effect is implementation-defined: some implementations do nothing, while some implementations clear the std::string member currently used as the buffer and begin using the user-supplied character array of size
n
, whose first element is pointed to by s
, as the buffer and the input/output character sequence.此功能是受保护的虚拟,它可能只被称为通过
pubsetbuf()
或来自std::basic_stringbuf
一个用户定义的类的成员函数.原文:
This function is protected virtual, it may only be called through
pubsetbuf()
or from member functions of a user-defined class derived from std::basic_stringbuf
.目录 |
[编辑] 参数
s | - | 指针的第一个字节的用户提供的缓冲区,则返回null
原文: 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::basic_streambuf
.原文:
*this, cast to the base class
std::basic_streambuf
.[编辑] 注释
过时的流缓冲std::strstreambufBoost.Iostreams的设备,
boost::basic_array
可用于实现I / O缓冲用户提供的字符数组中可移植的方式.原文:
The deprecated stream buffer std::strstreambuf or the boost.IOStreams device
boost::basic_array
may be used to implement I/O buffering over a user-provided char array in portable manner.[编辑] 示例
stringstream类的函数setbuf功能测试
原文:
Test for the stringstream's setbuf functionality
#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'; }
输出:
3.14 (on GNU g++/libstdc++ and SunPro C++/roguewave) <nothing> (on MS Visual Studio 2010, SunPro C++/stlport4, CLang++/libc++)
[编辑] 另请参阅
调用setbuf() (公共成员函数of std::basic_streambuf )
|