Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
streambuf
streambuf::streambuf
streambuf::~streambuf
public members:
streambuf::getloc
streambuf::in_avail
streambuf::pubimbue
streambuf::pubseekoff
streambuf::pubseekpos
streambuf::pubsetbuf
streambuf::pubsync
streambuf::sbumpc
streambuf::sgetc
streambuf::sgetn
streambuf::snextc
streambuf::sputbackc
streambuf::sputc
streambuf::sputn
streambuf::sungetc
protected members:
streambuf::eback
streambuf::egptr
streambuf::epptr
streambuf::gbump
streambuf::gptr
streambuf::pbase
streambuf::pbump
streambuf::pptr
streambuf::setg
streambuf::setp
virtual prot. members:
streambuf::imbue
streambuf::overflow
streambuf::pbackfail
streambuf::seekoff
streambuf::seekpos
streambuf::setbuf
streambuf::showmanyc
streambuf::sync
streambuf::uflow
streambuf::underflow
streambuf::xsgetn
streambuf::xsputn


streambuf::sputn

public member function
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