std::basic_ostream::put(3)
π std::basic_ostream::put(3) π
okay so bestie, welcome to the std::basic_ostream::put(3) page from the C++ Standard Libary manual β yes, that spelling, it's giving vintage typo energy π
. This is the vibe check for the put member of std::basic_ostream, and it's lowkey iconic.
β¨ NAME β¨
std::basic_ostream::put β std::basic_ostream::put
... the same name twice, no cap. That's literally what it is π«Ά.
β¨ Synopsis β¨
basic_ostream& put( char_type ch );
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 π¬
// Run this code
#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 π¨οΈ
a
Unformatted output: fail=0 bad=1
Formatted output: fail=1 bad=1
π See also π
operator<<(std::basic_ostream)β inserts character data or insert into rvalue stream (function template)writeβ inserts blocks of characters (public member function)
xoxo bestie π«Ά β source/version: http://cppreference.com, date: 2024.06.10 π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms