std::basic_streambuf<CharT,Traits>:: sputn, std::basic_streambuf<CharT,Traits>:: xsputn
From cppreference.net
<
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() が実際に呼び出されるか、またはその効果が他の方法で達成されるかは未規定です。
目次 |
パラメータ
(なし)
戻り値
正常に書き込まれた文字数。
注記
「他の手段によって達成される」ことは、中間バッファリングなしでの一括入出力を可能にします:これは 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 |
xsputn()
は常に
overflow()
を呼び出していた
pptr
(
)
==
epptr
(
)
の場合
|
実際には呼び出す必要はない |
関連項目
|
xsgetn
を呼び出す
(公開メンバ関数) |