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