fputs
来自 zh.cppreference.net
| 定义于头文件 <stdio.h>
|
||
int fputs( const char* str, FILE* stream );
|
(直到C99) | |
int fputs( const char* restrict str, FILE* restrict stream );
|
(自C99开始) | |
将空终止字符串str中的每个字符写入输出流stream,如同重复执行fputc。
空终止字符串str中的终止空字符不会被写入。
参数
| str | - | 要写入的空终止字符串 |
| stream | - | 输出流 |
返回值
成功时返回非负值。
失败时返回EOF并设置error指示器(参见ferror())在stream上。
注意
相关函数puts在输出后追加一个换行符,而fputs直接写入字符串,不做修改。
不同的实现返回不同的非负数值:有些返回最后写入的字符,有些返回写入的字符数(如果字符串长于此值则返回INT_MAX),有些仅返回一个非负常量(例如零)。
示例
运行此代码
#include <stdio.h>
int main(void)
{
int rc = fputs("Hello World", stdout);
if (rc == EOF)
perror("fputs()"); // POSIX requires that errno is set
}
输出:
Hello World
参考文献
- C23标准(ISO/IEC 9899:2024):
- 7.21.7.4 fputs函数(页码:TBD)
- C17标准(ISO/IEC 9899:2018):
- 7.21.7.4 fputs函数(页码:TBD)
- C11标准(ISO/IEC 9899:2011):
- 7.21.7.4 fputs函数(页码:331-332)
- C99标准(ISO/IEC 9899:1999):
- 7.19.7.4 fputs函数(页码:297)
- C89/C90标准(ISO/IEC 9899:1990):
- 4.9.7.4 fputs函数
另请参阅
(C99)(C11)(C11)(C11)(C11) |
将格式化输出打印到stdout、文件流或缓冲区 (函数) |
| 将字符串写入stdout (函数) | |
| 从文件流获取字符串 (函数) | |
C++文档中关于fputs
| |