public member function

std::streambuf::sputn

<streambuf>
streamsize sputn ( const char * s, streamsize n );
Write a sequence of characters
Calls the protected virtual member xsputn, which puts up to n characters from the array specified in parameter s into the output sequence.

The function behaves as if successive calls to sputc were made with each character, until n characters were written or until sputc would have returned EOF (or traits::eof() for other traits).

Parameters

s
Pointer to the sequence of characters to be output.
n
Number of character to be put. This is an integer value of type streamsize.

Return Value

The number of characters written, returned as a value of type streamsize.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// sputn () example
#include <fstream>
using namespace std;

int main () {

  char sentence[]= "Sample sentence";
  streambuf * pbuf;
  ofstream ostr ("test.txt");

  pbuf = ostr.rdbuf();

  pbuf->sputn (sentence,sizeof(sentence)-1);

  ostr.close();

  return 0;
}


This short example writes a sentence to a file using streambuf's member sputn.

Basic template member declaration

( basic_streambuf<charT,traits> )
1
2
typedef traits::char_type char_type;
streamsize sputn ( const char_type* s, streamsize n );


See also