首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::fputs

Defined in header <cstdio>

int fputs( const char* str, std::FILE* stream );

从以空结尾的字符串中写入每个字符。str到输出流stream,好像通过反复执行std::fputc...

终止空字符的str不是写的。

参数

str

-

null-terminated character string to be written

stream

-

output stream

返回值

在成功时,返回一个非负值.

失败时,返回EOF并设置误差指标%28见std::ferror29%stream...

注记

相关功能std::puts将换行符追加到输出,而std::fputs写入未修改的字符串。

不同的实现返回不同的非负数:一些返回最后写好的字符,一些返回写入%28或int的字符数。[医]如果字符串长度大于%29,则有些只返回非负常量(如零)。

二次

代码语言:javascript
复制
#include <cstdio>
 
int main(void)
{
    int rc = std::fputs("Hello World", stdout);
 
    if (rc == EOF)
       std::perror("fputs()"); // POSIX requires that errno is set
}

二次

产出:

二次

代码语言:javascript
复制
Hello World

二次

另见

printffprintfsprintfsnprintf (C++11)

prints formatted output to stdout, a file stream or a buffer (function)

puts

writes a character string to stdout (function)

fputws

writes a wide string to a file stream (function)

fgets

gets a character string from a file stream (function)

c fput文档

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券