约 1074 字

约 5 分钟

#C 语言标准库函数 getwc

#include <wchar.h>

wint_t getwc(FILE *stream);

说明

从指定流读取一个宽字符。

宽字符 I/O 使用流定向。一个流确定定向后,应按相同定向操作。宏实现可能多次求值流参数,应使用没有副作用的表达式。

自 C95 起提供。

参数

  • stream - 可进行宽字符 I/O 的有效流。

返回值

  • 返回转换到 wint_t 的读取值。文件末尾或错误时返回 WEOF。

#示例

#include <wchar.h>
#include <stdio.h>

int main(void)
{
    FILE *stream = tmpfile();
    if (stream == NULL) {
        return 1;
    }
    if (fputws(L"A\n", stream) < 0 || fseek(stream, 0, SEEK_SET) != 0) {
        fclose(stream);
        return 1;
    }
    int ok = getwc(stream) == L'A';
    int closed = fclose(stream);
    return !ok || closed != 0;
}

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28