std::fputc, std::putc
来自cppreference.com
| 在标头 <cstdio> 定义
|
||
| |
||
写入字符 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 (函数) | |
fputc, putc 的 C 文档
| |