fputwc, putwc
From cppreference.net
File input/output
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<wchar.h>
|
||
|
wint_t fputwc
(
wchar_t
ch,
FILE
*
stream
)
;
|
(1) | (C95 起) |
|
wint_t putwc
(
wchar_t
ch,
FILE
*
stream
)
;
|
(2) | (C95 起) |
将宽字符 ch 写入到指定的输出流 stream 中。
2)
可能作为宏实现,并可能多次求值
stream
。
目录 |
参数
| ch | - | 待写入的宽字符 |
| stream | - | 输出流 |
返回值
成功时返回 ch 的副本。
失败时返回 WEOF 并设置 error 指示器(参见 ferror() )于 stream 上。
如果发生编码错误,则额外将 errno 设置为 EILSEQ 。
示例
运行此代码
#include <errno.h> #include <locale.h> #include <stdio.h> #include <stdlib.h> #include <wchar.h> int main(void) { setlocale(LC_ALL, "en_US.utf8"); errno = 0; if (fputwc(L'🍌', stdout) == WEOF) { if (errno == EILSEQ) puts("Encoding error in fputwc."); else puts("I/O error in fputwc."); return EXIT_FAILURE; } }
可能的输出:
🍌
参考文献
- C23 标准 (ISO/IEC 9899:2024):
-
- 7.31.3.3 fputwc 函数 (页: 430)
-
- 7.31.3.8 putwc 函数 (页: 431-432)
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.29.3.3 fputwc 函数 (页: 308)
-
- 7.29.3.8 putwc 函数 (页: 310)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.29.3.3 fputwc 函数 (页: 422-423)
-
- 7.29.3.8 putwc 函数 (页: 424)
- C99标准(ISO/IEC 9899:1999):
-
- 7.24.3.3 fputwc函数(页码:368)
-
- 7.24.3.8 putwc函数(页码:370)
参考
|
向文件流写入一个字符
(函数) |
|
|
(C95)
|
向文件流写入一个宽字符串
(函数) |
|
(C95)
|
从文件流获取一个宽字符
(函数) |
|
C++ 文档
for
fputwc
|
|