streambuf::sputc
int sputc ( char c );
streambuf
  cplusplus.com  

Store character at current put position and increase put pointer.
  Character c is stored at current put position and the put pointer is increased by one.

Parameters.

c
Character to be put.

Return Value.
  In case of success the character output is returned,
  Otherwise the return value depends on protected virtual member overflow, whose default behavior in this case is to return EOF.

Example.

// 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 in the standard input to a file. This is done until a dot character (.) is introduced.

Basic template member declaration ( basic_streambuf<charT,traits> ):
typedef traits::char_type char_type;
typedef traits::int_type int_type;
int_type sputc ( char_type c );

See also.
  sbumpc, sgetn, sputn
  streambuf class


© The C++ Resources Network, 2001