std::basic_streambuf<CharT,Traits>:: pubsetbuf, std::basic_streambuf<CharT,Traits>:: setbuf
From cppreference.net
<
cpp
|
io
|
basic streambuf
|
public
:
basic_streambuf < CharT, Traits > * pubsetbuf ( char_type * s, std:: streamsize n ) |
(1) | |
|
protected
:
virtual basic_streambuf < CharT, Traits > * setbuf ( char_type * s, std:: streamsize n ) |
(2) | |
1)
最も派生したクラスの
setbuf
(
s, n
)
を呼び出します。
2)
この関数の基底クラスバージョンは何も効果を持ちません。派生クラスは、制御対象の文字シーケンス(バッファ)をユーザー提供の配列で削除または置換するため、またはその他の実装固有の目的のために、この関数をオーバーライドすることができます。
目次 |
パラメータ
| s | - |
ユーザー提供バッファ内の最初の
CharT
へのポインタ
|
| n | - |
ユーザー提供バッファ内の
CharT
要素の数
|
戻り値
1)
setbuf
(
s, n
)
の戻り値。
2)
this
例
読み取り用に10KBのバッファを提供します。Linuxでは、straceユーティリティを使用して実際に読み取られたバイト数を観察できます。
このコードを実行
#include <fstream> #include <iostream> #include <string> int main() { int cnt = 0; std::ifstream file; char buf[1024 * 10 + 1]; file.rdbuf()->pubsetbuf(buf, sizeof buf); file.open("/usr/share/dict/words"); for (std::string line; getline(file, line);) ++cnt; std::cout << cnt << '\n'; }
出力例:
356010
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 158 | C++98 |
setbuf
のデフォルト動作は
gptr() がnullでなく、かつ egptr() と等しくない場合のみ規定されていた |
すべての場合において
何も行わないものとして規定 |
関連項目
|
[virtual]
|
制御された文字シーケンスを配列で置き換えようとする
(
std::basic_stringbuf<CharT,Traits,Allocator>
の仮想保護メンバ関数)
|
|
[virtual]
|
ユーザー提供のバッファを設定するか、このfilebufを非バッファリングにする
(
std::basic_filebuf<CharT,Traits>
の仮想保護メンバ関数)
|
|
[virtual]
|
制御された文字シーケンスを配列で置き換えようとする
(
std::strstreambuf
の仮想保護メンバ関数)
|
|
ファイルストリームのバッファを設定する
(関数) |