std::puts(3)

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

πŸ’… std::puts(3) β€” C++ Standard Library, but make it cute πŸ’…

Okay so bestie, this is the manual page for std::puts, straight from the C++ Standard Library. She writes strings, she adds newlines, she’s lowkey iconic. Let’s get into it. πŸŽ€


πŸŽ€ NAME πŸŽ€

std::puts β€” literally std::puts. That’s the name, no cap. She lives in the C++ Standard Library and her whole thing is writing a string plus a newline to stdout. ✨


✨ Synopsis ✨

Defined in header <cstdio>:

int puts( const char *str );

Writes every character from the null-terminated string str and one additional newline character '\n' to the output stream stdout, as if by repeatedly executing std::fputc.

The terminating null character from str is not written. Not even a little. πŸ™ˆ


🌸 Parameters 🌸

  • str β€” character string to be written

πŸ’– Return value πŸ’–

  • On success, returns a non-negative value.
  • On failure, returns EOF and sets the error indicator (see std::ferror) on stdout.

πŸ¦‹ Notes πŸ¦‹

  • The std::puts function appends the newline character to the output, while the std::fputs function does not. That’s the whole difference, and she’s serving it. πŸ’…
  • 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.
  • A typical cause of failure for std::puts is running out of space on the file system, when stdout is redirected to a file.

πŸŽ€ Example πŸŽ€

// Run this code

#include <cstdio>

int main()
{
    int rc = std::puts("Hello World");

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

⭐ Output ⭐

Hello World

πŸ”₯ See also πŸ”₯

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

Source/version/date vibes: http://cppreference.com, 2024.06.10, for this std::puts(3) page β€” mwah, go slay those null-terminated strings bestie πŸ’‹βœ¨πŸ«Ά

πŸ“¦ where this page comes from