|
Behaves as an UnformattedOutputFunction
. After constructing and checking the sentry object, writes the character ch
to the output stream.
If the output fails for any reason, sets badbit
.
Parameters
ch | - | character to write |
Return value
*this
.
Notes
This function is not overloaded for the types signed char
or unsigned char
, unlike the formatted operator<<
Unlike formatted output functions, this function does not set the failbit
if the output fails.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <fstream> #include <iostream> int main() { std::cout.put( 'a' ); // normal usage std::cout.put( '\n' ); std::ofstream s( "/does/not/exist/" ); s.clear(); // pretend the stream is good std::cout << "Unformatted output: " ; s.put( 'c' ); // this will set badbit, but not failbit std::cout << " fail=" << bool (s.rdstate() & s.failbit); std::cout << " bad=" << s.bad() << '\n' ; s.clear(); std::cout << "Formatted output: " ; s << 'c' ; // this will set badbit and failbit std::cout << " fail=" << bool (s.rdstate() & s.failbit); std::cout << " bad=" << s.bad() << '\n' ; } |
Output:
1 2 3 | a Unformatted output: fail=0 bad=1 Formatted output: fail=1 bad=1 |
See also
inserts character data (function template) | |
inserts blocks of characters (public member function) |
Please login to continue.