std::putchar
来自cppreference.com
| 在标头 <cstdio> 定义
|
||
| |
||
写入字符 ch 到 stdout。内部在写入前转换字符为 unsigned char。
等价于 putc(ch, stdout)。
参数
| ch | - | 要写入的字符 |
返回值
成功时,返回被写入字符。
失败时,返回 EOF 并设置 stdout 上的“错误”指示器(见 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
参阅
| 写字符到文件流 (函数) | |
putchar 的 C 文档
| |