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::sputc

public member function
int sputc ( char c );

Store character at current put position and increase put pointer

The character c is stored at the current put position and then the put pointer is increased to point to the next character position.

During its operation, the function will call the protected virtual member function overflow if the put pointer pptr points to the same position as the end pointer epptr before the call (or if it is a null pointer).

Parameters

c
Character to be put.

Return Value

In case of success, the character put is returned (type-casted to the appropiate return type).
Otherwise, returns EOF (or traits::eof() for other traits).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// typewriter - sputc () example
#include <iostream>
#include <fstream>
using namespace std;
int main () {
  char ch;
  streambuf * pbuf;
  ofstream ostr ("test.txt");
  pbuf = ostr.rdbuf();
  do {
     ch = cin.get();
     pbuf->sputc(ch);
  } while (ch!='.');
  ostr.close();
  return 0;
}


Once executed, this example writes any character written to the standard input to a file. This is repeated until a dot character (.) is introduced.

Basic template member declaration

( basic_streambuf<charT,traits> )
1
2
3
typedef traits::char_type char_type;
typedef traits::int_type int_type;
int_type sputc ( char_type c );


See also