名稱空間
變體
操作

std::putchar

來自 cppreference.com
< 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

[編輯] 參閱

向檔案流寫入一個字元
(函式) [編輯]
C 文件 關於 putchar