Namespaces
Variants

std:: putchar

From cppreference.net
< cpp ‎ | io ‎ | c
定义于头文件 <cstdio>
int putchar ( int ch ) ;

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

等价于 std:: putc ( ch, stdout )

目录

参数

ch - 待写入的字符

返回值

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

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

示例

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

可能的输出:

abcdefghijklmnopqrstuvwxy
r = 0x1024
$
r = 0x24

参见

将字符写入文件流
(函数)
C 文档 for putchar