名稱空間
變體
操作

std::fputc, std::putc

來自 cppreference.com
< cpp‎ | io‎ | c
 
 
 
 
定義於標頭檔案 <cstdio>
int fputc( int ch, std::FILE* stream );
int putc( int ch, std::FILE* stream );

將字元 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'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 documentation for fputc, putc