std::fputc, std::putc
来自 cppreference.cn
定义于头文件 <cstdio> |
||
将字符 ch 写入给定的输出流 stream。
在内部,字符在写入之前被转换为 unsigned char。
在 C 中,putc() 可能被实现为宏,这在 C++ 中是不允许的。因此,调用 std::fputc() 和 std::putc() 始终具有相同的效果。
内容 |
[编辑] 参数
ch | - | 要写入的字符 |
stream | - | 输出流 |
[编辑] 返回值
成功时,返回写入的字符。
失败时,返回 EOF 并设置 错误 指示符(参见 std::ferror())在 stream 上。
[编辑] 示例
运行此代码
#include <cstdio> int main() { for (char c = 'a'; c != 'z'; c++) std::putc(c, stdout); // putchar's return value is not equal to the argument 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
|