Namespaces
Variants

std:: fputc, std:: putc

From cppreference.net
< cpp ‎ | io ‎ | c
定义于头文件 <cstdio>
int fputc ( int ch, std:: FILE * stream ) ;
int putc ( int ch, std:: FILE * stream ) ;

将字符 ch 写入到指定的输出流 stream

在内部,该字符在写入前会被转换为 unsigned char

在C语言中, putc ( ) 可能被实现为宏,这在C++中是不允许的。因此,调用 std :: fputc ( ) std :: putc ( ) 始终具有相同的效果。

目录

参数

ch - 待写入的字符
stream - 输出流

返回值

成功时,返回已写入的字符。

失败时返回 EOF 并在 stream 上设置错误指示器(参见 std::ferror() )。

示例

#include <cstdio>
int main()
{
    for (char c = 'a'; c != 'z'; c++)
        std::putc(c, stdout);
    // putchar 的返回值不等于参数
    int r = 0x102A;
    std::printf("\nr = 0x%x\n", r);
    r = std::putchar(r);
    std::printf("\nr = 0x%x\n", r);
}

可能的输出:

abcdefghijklmnopqrstuvwxy
r = 0x102A
*
r = 0x2A

参见

stdout 写入一个字符
(函数)
C 文档 用于 fputc , putc