名稱空間
變體
操作

std::fputwc

來自 cppreference.com
< cpp‎ | io‎ | c
 
 
 
 
在標頭檔案 <cwchar> 中定義
std::wint_t fputwc( wchar_t ch, std::FILE* stream );
(1)
std::wint_t putwc( wchar_t ch, std::FILE* stream );
(2)

將寬字元 ch 寫入到給定的輸出流 stream

2) 可實現為宏,且可對 stream 求值不止一次。

目錄

[編輯] 引數

ch - 要寫入的寬字元
stream - 輸出流

[編輯] 返回值

成功時為 ch,失敗時為 WEOF。如果發生編碼錯誤,則 errno 被設定為 EILSEQ

[編輯] 示例

#include <cerrno>
#include <clocale>
#include <cstdio>
#include <cstdlib>
#include <cwchar>
#include <initializer_list>
 
int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
 
    for (const wchar_t ch :
    {
        L'\u2200', // Unicode name: "FOR ALL"
        L'\n',
        L'∀',
    })
    {
        if (errno = 0; std::fputwc(ch, stdout) == WEOF)
        {
            std::puts(errno == EILSEQ
                ? "Encoding error in fputwc"
                : "I/O error in fputwc"
            );
            return EXIT_FAILURE;
        }
    }
    return EXIT_SUCCESS;
}

可能的輸出

∀
∀

[編輯] 參閱

向檔案流寫入一個字元
(函式) [編輯]
向檔案流寫入一個寬字串
(函式) [編輯]
從檔案流中獲取一個寬字元
(函式) [編輯]
C 文件 關於 fputwc
English 日本語 中文(简体) 中文(繁體)