感谢!
请问如何将一个wchar_t数组用freopen的方式输出到文件?
输出 wchar_t 之前,需要使用 setlocale 语句设置标准输出的代码页。
参考以下代码:
#include <stdio.h>
#include <locale.h>
int main()
{
// 设置标准输出的代码页
setlocale(LC_ALL, ".UTF8"); // 输出文件为 utf8 编码
// setlocale(LC_ALL, "zh-CN"); // 输出文件为 ANSI 编码(不推荐)
FILE* stream = freopen("D:\\test.txt", "w", stdout);
wprintf(L"厉害了我的国");
fclose(stream);
return 0;
}