std::basic_streambuf<CharT,Traits>::sputn, std::basic_streambuf<CharT,Traits>::xsputn
From cppreference.com
< cpp | io | basic streambuf
| std::streamsize sputn( const char_type* s, std::streamsize count ); |
(1) | |
| protected: virtual std::streamsize xsputn( const char_type* s, std::streamsize count ); |
(2) | |
1) 最も派生したクラスの xsputn(s, count) を呼び出します。
2) s が指す配列の先頭から count 個の文字を出力シーケンスに書き込みます。文字は、sputc() を繰り返し呼び出すかのように書き込まれます。書き込みは、count 個の文字が書き込まれるか、または sputc() の呼び出しが Traits::eof() を返した場合に停止します。
出力領域が満杯になった場合(pptr() == epptr())、overflow() が実際に呼び出されるか、またはその効果が他の手段で達成されるかは未規定です。
目次 |
[編集] パラメータ
(なし)
[編集] 戻り値
正常に書き込まれた文字数。
[編集] 注記
「他の手段で達成される」とは、中間バッファリングなしのバルクI/Oを許可します。これは、一部の実装で std::ofstream::write() が単にポインタを適切なシステムコールに渡す方法です。
[編集] 例
このコードを実行
#include <iostream> #include <sstream> int main() { std::ostringstream s1; std::streamsize sz = s1.rdbuf()->sputn("This is a test", 14); s1 << '\n'; std::cout << "The call to sputn() returned " << sz << '\n' << "The output sequence contains " << s1.str(); std::istringstream s2; sz = s2.rdbuf()->sputn("This is a test", 14); std::cout << "The call to sputn() on an input stream returned " << sz << '\n'; }
出力
The call to sputn() returned 14 The output sequence contains This is a test The call to sputn() on an input stream returned 0
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 565 | C++98 | pptr() == epptr() の場合、overflow() が常に呼び出されていました。 | 実際には呼び出す必要はありませんでした。 |
[編集] 関連項目
| xsgetn() を呼び出す (public member function) |