std::basic_stringbuf<CharT,Traits,Allocator>::setbuf
From cppreference.com
< cpp | io | basic stringbuf
| 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へのポインタ、またはヌル |
| n | - | ユーザー提供バッファ内のCharT要素の数、またはゼロ |
[編集] 戻り値
this
[編集] 注記
非推奨のストリームバッファstd::strstreambuf、またはBoost.IOStreamsデバイスboost::basic_arrayは、移植可能な方法でユーザー提供のchar配列 über された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() を呼び出す ( std::basic_streambuf<CharT,Traits> の public メンバ関数) |