文本文件中的本地化字符无效

时间:2013-02-21 19:12:29

标签: c unicode wchar-t c89

我学习C语言。我需要用Unicode数据创建一些文本文件。我写了这样的代码:

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

int main(int argc, char *argv[]) {

    wchar_t *s1 = L"Привет, мир!\n";
    wchar_t *s2 = L"Hello, World!";

    FILE *fp = fopen("./hello.txt", "w");

    fputws(s1, fp);
    fputws(s2, fp);

    fclose(fp);

    exit(EXIT_SUCCESS);
}

但我得到了这样的结果:

??????, ???!
Hello, World!

为什么我没有得到俄罗斯人?

1 个答案:

答案 0 :(得分:2)

您运行该程序的终端中的区域设置可能有问题。如果是这样,您只需要设置这样的语言环境:

setlocale(LC_CTYPE,"");

更多信息here

相关问题