Difference between revisions of "cpp/io/c/fputs"
From cppreference.com
(+see c) |
m (fmt) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | {{cpp/title | fputs}} | + | {{cpp/title|fputs}} |
− | {{cpp/io/c/ | + | {{cpp/io/c/navbar}} |
− | {{ddcl | header=cstdio | | + | {{ddcl|header=cstdio| |
− | int fputs( const char *str, FILE *stream ); | + | int fputs( const char* str, std::FILE* stream ); |
}} | }} | ||
− | Writes | + | Writes every character from the null-terminated string {{tt|str}} to the output stream {{tt|stream}}, as if by repeatedly executing {{lc|std::fputc}}. |
+ | |||
+ | The terminating null character from {{tt|str}} is not written. | ||
===Parameters=== | ===Parameters=== | ||
− | {{ | + | {{par begin}} |
− | {{ | + | {{par|str|null-terminated character string to be written}} |
− | {{ | + | {{par|stream|output stream}} |
− | {{ | + | {{par end}} |
===Return value=== | ===Return value=== | ||
− | + | On success, returns a non-negative value | |
+ | |||
+ | On failure, returns {{lc|EOF}} and sets the ''error'' indicator (see {{lc|std::ferror}}) on {{tt|stream}}. | ||
+ | |||
+ | ===Notes=== | ||
+ | The related function {{lc|std::puts}} appends a newline character to the output, while {{tt|std::fputs}} writes the string unmodified. | ||
+ | |||
+ | Different implementations return different non-negative numbers: some return the last character written, some return the number of characters written (or {{lc|INT_MAX}} if the string was longer than that), some simply return a non-negative constant such as zero. | ||
+ | |||
+ | ===Example=== | ||
+ | {{example|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=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc|cpp/io/c/dsc fprintf}} |
− | {{ | + | {{dsc inc|cpp/io/c/dsc puts}} |
− | {{ | + | {{dsc inc|cpp/io/c/dsc fputws}} |
− | {{ | + | {{dsc inc|cpp/io/c/dsc fgets}} |
− | {{ | + | {{dsc see c|c/io/fputs}} |
+ | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + |
Latest revision as of 12:56, 29 November 2022
Defined in header <cstdio>
|
||
int fputs( const char* str, std::FILE* stream ); |
||
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.
Contents |
[edit] Parameters
str | - | null-terminated character string to be written |
stream | - | output stream |
[edit] Return value
On success, returns a non-negative value
On failure, returns EOF and sets the error indicator (see std::ferror) on stream
.
[edit] Notes
The related function std::puts appends a newline character to the output, while std::fputs
writes the string unmodified.
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.
[edit] 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
[edit] See also
(C++11) |
prints formatted output to stdout, a file stream or a buffer (function) |
writes a character string to stdout (function) | |
writes a wide string to a file stream (function) | |
gets a character string from a file stream (function) | |
C documentation for fputs
|