sputn
描述 (Description)
它用于放置字符序列,并使用相同的参数s和n调用受保护的虚拟成员xsputn。
声明 (Declaration)
以下是std :: streambuf :: sputn的声明。
streamsize sputn (const char* s, streamsize n);
参数 (Parameters)
s - 指向要写入的字符序列的指针。
n - 要写入的字符数。
返回值 (Return Value)
它返回写入的字符数。
异常 (Exceptions)
Basic guarantee - 如果抛出异常,则流缓冲区处于有效状态。
数据竞争 (Data races)
它修改了流缓冲区对象。
例子 (Example)
在下面的例子中解释了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;
}