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
streambuf::sbumpc | Get current character and increase get pointer (public member function) |
|