std::puts
Defined in header <cstdio> | | |
|---|---|---|
int puts( const char *str ); | | |
从以空结尾的字符串中写入每个字符。str和一个额外的换行符'\n'到输出流stdout,好像通过反复执行std::fputc...
终止空字符的str不是写的。
参数
str | - | character string to be written |
|---|
返回值
在成功时,返回一个非负值.
失败时,返回EOF并设置误差指标%28见std::ferror29%stream...
注记
大std::puts函数将换行符追加到输出,而std::fputs功能没有。
不同的实现返回不同的非负数:一些返回最后写好的字符,一些返回写入%28或INT_MAX如果字符串长度大于%29,则有些只返回一个非负常量.
一个典型的失败原因std::puts文件系统上的空间不足,而stdout被重定向到文件。
例
二次
#include <cstdio>
int main()
{
int rc = std::puts("Hello World");
if (rc == EOF)
std::perror("puts()"); // POSIX requires that errno is set
}二次
产出:
二次
Hello World二次
另见
fputs | writes a character string to a file stream (function) |
|---|---|
printffprintfsprintfsnprintf (C++11) | prints formatted output to stdout, a file stream or a buffer (function) |
C文件
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

