std:: puts
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<cstdio>
|
||
|
int
puts
(
const
char
*
str
)
;
|
||
将空终止字符串
str
中的每个字符以及一个额外的换行符
'
\n
'
写入输出流
stdout
,其效果类似于重复执行
std::fputc
。
来自
str
的终止空字符不会被写入。
目录 |
参数
| str | - | 要写入的字符串 |
返回值
成功时,返回非负值
失败时,返回
EOF
并在
stdout
上设置错误指示器(参见
std::ferror
)。
注释
std::puts
函数会在输出末尾追加换行符,而
std::fputs
函数则不会。
不同实现会返回不同的非负数:有些返回最后写入的字符,有些返回写入的字符数量(若字符串长度超过限制则返回 INT_MAX ),有些仅返回一个非负常量。
std::puts
失败的典型原因是文件系统空间不足,这种情况通常发生在
stdout
被重定向到文件时。
示例
#include <cstdio> int main() { int rc = std::puts("Hello World"); if (rc == EOF) std::perror("puts()"); // POSIX要求必须设置errno }
输出:
Hello World
参见
|
将字符串写入文件流
(函数) |
|
|
(C++11)
|
将格式化输出打印到
stdout
、文件流或缓冲区
(函数) |
|
C 文档
关于
puts
|
|