streambuf::sputn
streamsize sputn ( const char * s, streamsize n );
streambuf
  cplusplus.com  

Write some characters.
  Calls protected virtual member xsputn(s,n), whose default behavior is to write n characters from the array specified in parameter s to the output sequence of the stream buffer.

Parameters.

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

Return Value.
  The number of characters written. The value is returned as an object of type streamsize.

Example.

// 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> ):
typedef traits::char_type char_type;
streamsize sputn ( char_type* s, streamsize n );

See also.
  sgetn, sputc
  streambuf class


© The C++ Resources Network, 2001