std::fputws(3)

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

πŸ’– std::fputws πŸ’–

okay bestie, welcome to the std::fputws(3) page from the C++ Standard Libary β€” and yes, that's literally how the header spells β€œLibrary,” so we’re keeping it exactly as-is πŸ˜­πŸ’…. This function is giving wide-character output but make it a whole vibe, and we’re gonna get into every single detail. No cap.


πŸŽ€ NAME πŸŽ€

std::fputws β€” std::fputws. That’s it. She’s concise, she’s iconic, she said β€œmy name is my name” πŸ’β€β™€οΈβœ¨.

✨ Synopsis ✨

Defined in header <cwchar>:

int fputws( const wchar_t* str, std::FILE* stream );

So here’s the tea: std::fputws writes every wide character from the null-terminated wide string str to the output stream stream, as if by repeatedly executing std::fputwc. 🫢

And the important little detail: the terminating null wide character from str is not written. Not me being dramatic, that’s just the rule, bestie. 🚫

🌸 Parameters 🌸

  • str β€” null-terminated wide string to be written.
  • stream β€” output stream.

πŸ’œ Return value πŸ’œ

  • On success, returns a non-negative value πŸŽ‰
  • On failure, returns EOF and sets the error indicator (see std::ferror) on stream 😭
lowkey important: that failure case is not a vibe. Check the error indicator on stream if you get EOF.

🧚 Example 🧚

// Run this code

#include <clocale>
#include <cstdio>
#include <cwchar>

int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    int rc = std::fputws(L"徑休みγͺさい", stdout);

    if (rc == EOF)
        std::perror("fputws()"); // POSIX requires that errno is set
}

🌈 Possible output 🌈

徑休みγͺさい

πŸ‘‘ See also πŸ‘‘

  • fputs β€” writes a character string to a file stream (function)
  • wprintf β€” prints formatted wide character output to stdout, a file stream or a buffer
  • fwprintf β€” (function)
  • swprintf
  • fputws β€” writes a wide string to a file stream (function)
  • fgetws β€” gets a wide string from a file stream (function)
  • C documentation for fputws

xoxo, this std::fputws(3) page is from http://cppreference.com, version/date 2024.06.10 β€” bye bestie, go write some wide strings πŸ’…πŸ«ΆπŸ’–

πŸ“¦ where this page comes from