cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : streambuf : sputc
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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

// 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> )
typedef traits::char_type char_type;
typedef traits::int_type int_type;
int_type sputc ( char_type c );

See also

streambuf::sbumpc Get current character and increase get pointer (public member function)
streambuf::sgetn Get sequence of characters (public member function)
streambuf::sputn Write a sequence of characters (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us