约 1148 字

约 6 分钟

#C 语言标准库函数 fwprintf

#include <wchar.h>

int fwprintf(FILE *restrict stream, const wchar_t *restrict format, ...);

说明

按格式向指定的文件流写出数据。

应使用宽定向或未定向的文件流。

按照格式说明提供参数,转换以当前 locale 的相应规则为准。

自 C95 起提供。

参数

  • stream - 参与输入输出的有效文件流。
  • format - 以空字符结束的格式串,包含普通字符和转换指令。
  • ... - 随转换指令提供的输出值。

返回值

  • 正常返回实际写出宽字符数,排除终止符。输出或编码错误时返回负值。

#示例

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

int main(void)
{
    FILE *stream = tmpfile();
    if (stream == NULL) {
        return 1;
    }
    int count = fwprintf(stream, L"item %d\n", 42);
    int close_status = fclose(stream);
    return count != 8 || close_status != 0;
}

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28