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 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

関連項目

ファイルストリームに文字を書き込む
(関数)