Cpp-standard-library-cpp-stringbuf-sputn
提供:Dev Guides
C ++ streambuf-sputn
説明
文字のシーケンスを配置するために使用され、同じ引数sおよびnで保護仮想メンバーxsputnを呼び出します。
宣言
- 以下は、std
- streambuf :: sputnの宣言です。
streamsize sputn (const char* s, streamsize n);
パラメーター
- s -書き込まれる文字のシーケンスへのポインタ。
- n -書き込む文字数。
戻り値
書き込まれた文字数を返します。
例外
基本的な保証-例外がスローされた場合、ストリームバッファは有効な状態です。
データの競合
ストリームバッファオブジェクトを変更します。
例
- 以下の例では、std
- streambuf :: sputnについて説明しています。
#include <iostream>
#include <fstream>
int main () {
const char sentence[]= "Sample sentence";
std::ofstream ostr ("test.txt");
if (ostr) {
std::streambuf * pbuf = ostr.rdbuf();
pbuf->sputn (sentence,sizeof(sentence)-1);
ostr.close();
}
return 0;
}