std::basic_ostream::put(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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