std::fputwc(3)

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

πŸ’– std::fputwc(3) πŸ’–

okay so bestie, welcome to the C++ Standard Libary manual moment β€” yes, that's the manual name, and we're talking about std::fputwc(3). It's a little wide-character writer with main character energy, and the vibe check is: write one wide char to a stream, periodt. ✨

πŸŽ€ NAME πŸŽ€

std::fputwc β€” std::fputwc. That's it. That's the name. No notes. πŸ’…

🌈 SYNOPSIS 🌈

Defined in header <cwchar>:

std::wint_t fputwc( wchar_t ch, std::FILE* stream ); (1)
std::wint_t putwc( wchar_t ch, std::FILE* stream );  (2)

Writes a wide character ch to the given output stream stream.

Bestie, read the fine print: (2) may be implemented as a macro and may evaluate stream more than once. That's not a drill, that's literally what the page says 🫢.

πŸ¦‹ PARAMETERS πŸ¦‹

  • ch β€” wide character to be written. The little Unicode star of the show πŸ’–
  • stream β€” the output stream. The destination. The place where ch is headed.

πŸ‘‘ RETURN VALUE πŸ‘‘

  • Returns ch on success. Slay βœ…
  • Returns WEOF on failure. Sad girl hours 😭
  • If an encoding error occurs, errno is set to EILSEQ.

🧚 EXAMPLE 🧚

The original literally says // Run this code, so we're running it. Here's the example, verbatim, no edits, no crumb snatching:

// Run this code

#include <cerrno>
#include <clocale>
#include <cstdio>
#include <cstdlib>
#include <cwchar>
#include <initializer_list>

int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");

    for (const wchar_t ch :
    {
        L'\u2200', // Unicode name: "FOR ALL"
        L'\n',
        L'βˆ€',
    })
    {
        if (errno = 0; std::fputwc(ch, stdout) == WEOF)
        {
            std::puts(errno == EILSEQ
                ? "Encoding error in fputwc"
                : "I/O error in fputwc"
            );
            return EXIT_FAILURE;
        }
    }
    return EXIT_SUCCESS;
}

πŸ¦‹ POSSIBLE OUTPUT πŸ¦‹

Possible output, exactly:

βˆ€
βˆ€

🌸 SEE ALSO 🌸

  • fputc β€” writes a character to a file stream.
  • putc β€” (function).
  • fputws β€” writes a wide string to a file stream (function).
  • fgetwc β€” gets a wide character from a file stream.
  • getwc β€” (function).
  • C documentation for fputwc.

okay bestie, that's the whole page πŸ’… it's from the C++ Standard Libary manual, the source/version line is http://cppreference.com, and the date is 2024.06.10 β€” std::fputwc(3), signing off with a little sparkle 🫢✨

πŸ“¦ where this page comes from