Namespaces
Variants

std::basic_stringbuf<CharT,Traits,Allocator>:: setbuf

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

s がヌルポインタであり、かつ n がゼロの場合、この関数は何も行いません。

そうでない場合、その効果は実装定義です:一部の実装では何も行わず、一部の実装では現在バッファとして使用されている std::string メンバーをクリアし、サイズ n のユーザー提供の文字配列(その最初の要素は s が指す)をバッファおよび入出力文字シーケンスとして使用し始めます。

この関数はprotected virtualであり、 pubsetbuf() を通じて、またはユーザー定義の std::basic_stringbuf から派生したクラスのメンバー関数からのみ呼び出すことができます。

目次

パラメータ

s - ユーザー提供バッファ内の最初のCharTへのポインタ、またはnull
n - ユーザー提供バッファ内のCharT要素の数、またはゼロ

戻り値

this

注記

非推奨のストリームバッファ std:: strstreambuf またはboost.IOStreamsデバイス boost::basic_array を使用して、ユーザー提供のchar配列上でのI/Oバッファリングを移植性のある方法で実装できます。

stringstreamのsetbuf機能のテスト。

#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 を呼び出す setbuf ( )
( std::basic_streambuf<CharT,Traits> の公開メンバ関数)