std::fputs(3)

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

πŸ’– NAME πŸ’–

okay bestie, welcome to std::fputs(3) from the C++ Standard Libary manual β€” yes, that's the manual name, and yes, the typo is part of the lore πŸ’€. The name section is literally std::fputs β€” std::fputs, which is giving "I said what I said" energy πŸ’….


πŸ¦‹ Synopsis πŸ¦‹

Defined in header <cstdio>:

int fputs( const char* str, std::FILE* stream );

It writes every character from the null-terminated string str to the output stream stream, as if by repeatedly executing std::fputc. The terminating null character from str is not written, bestie β€” that little \0 stays home 🫢.


🌸 Parameters 🌸

  • str β€” null-terminated character 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 😭.


🧠 Notes 🧠

The related function std::puts appends a newline character to the output, while std::fputs writes the string unmodified. no cap, that newline is not invited to this party πŸ™ˆ.

Different implementations return different non-negative numbers: some return the last character written, some return the number of characters written (or INT_MAX if the string was longer than that), some simply return a non-negative constant such as zero. so like… don't build your whole personality on the exact return number, okay? πŸ’€


πŸŽ€ Example πŸŽ€

// Run this code

#include <cstdio>

int main(void)
{
    int rc = std::fputs("Hello World", stdout);

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

πŸ’» Output πŸ’»

Hello World

πŸ‘€ See also πŸ‘€

  • printf
  • fprintf β€” prints formatted output to stdout, a file stream or a buffer (function)
  • sprintf β€” (function)
  • snprintf β€” (C++11) (function)
  • puts β€” writes a character string to stdout (function)
  • fputws β€” writes a wide string to a file stream (function)
  • fgets β€” gets a character string from a file stream (function)
  • C documentation for fputs

source/version/date vibe check, bestie: http://cppreference.com Β· 2024.06.10 Β· std::fputs(3) πŸŒˆπŸ’–

πŸ“¦ where this page comes from