std::putchar
来自 cppreference.cn
定义于头文件 <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 return value is not equal to the argument 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 文档 关于 putchar
|