【发布时间】:2019-01-03 11:52:37
【问题描述】:
我正在尝试打印所有扩展的 ASCII 字符。我在论坛上找到了一个代码:
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#include <iostream>
int main(void) {
wchar_t c;
setlocale(LC_ALL, "C");
for (c = 128; c < 256; c++) {
wprintf(L"char nr %d: %lc\n", c, c);
}
printf("\n%s\n", setlocale(0, NULL));
std::cin.get();
std::cin.get();
return 0;
}
在屏幕截图中,您可以看到此代码在 windows 和 Linux 中的结果。我知道问题出在编码上,但我不知道如何解决。
【问题讨论】:
-
考虑gnome-terminal的设置?
-
linux中$LANG环境变量的值是多少?
-
这个程序是C++,不是C。代码没问题,问题出在你的终端/用于显示的程序上(使用宽字符时它不支持扩展ascii)。 Windows 使用支持扩展 ascii 的编码,
wprintf。 -
LANG = pl_PL.UTF-8,终端字符编码为UNICODE-utf8。
-
@KamilCuk 我该如何解决?