std::basic_streambuf<CharT,Traits>::sputn, std::basic_streambuf<CharT,Traits>::xsputn
提供: cppreference.com
< cpp | io | basic streambuf
std::streamsize sputn(const char_type* s, std::streamsize count ); | (1) | |
protected: virtualstd::streamsize xsputn(const char_type* s, std::streamsize count ); | (2) | |
1) 最も派生したクラスの
xsputn(s, count)
を呼びます。2)
s
によって最初の要素が指される文字配列から出力シーケンスに count
個の文字を書き込みます。 文字は sputc() を繰り返し呼んだかのように書き込まれます。 書き込みは count
個の文字が書き込まれるか、 sputc() の呼び出しが Traits::eof() を返すときに停止します。put 領域がいっぱい (pptr()== epptr()) になった場合、この関数は overflow() を呼ぶか、または他の何らかの未規定な方法によって overflow() の効果を達成するかもしれません。
目次 |
[編集]引数
(なし)
[編集]戻り値
書き込みに成功した文字数。
[編集]ノート
「未規定な方法によって overflow()
の効果を達成する」は中間バッファリングなしのバルク I/O を許容します。 これにより入出力ストリームのいくつかの実装では std::ofstream::write が単純に POSIX の write()
システムコールにポインタを渡すことができます。
[編集]例
Run this code
#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
[編集]関連項目
xsgetn() を呼びます (パブリックメンバ関数) |