n. *_* m. 5 c wine utf-8 mingw-w64
我有打印一些字符的 C 代码。我希望看到这些字符被打印出来,而不是字母汤,
\n#include <stdio.h>\nint main() {\n const char* test = "Greek: \xce\xb1\xce\xb2\xce\xb3\xce\xb4; German: \xc3\x9cbergr\xc3\xb6\xc3\x9fentr\xc3\xa4ger";\n printf("%s\\n", test);\n}\nRun Code Online (Sandbox Code Playgroud)\n什么有效:
\ngcc test.c -o test && ./testwinegcc test.c o test.exe && ./test.exex86_64-w64-mingw32-gcc -o test.exe test.cpp && wine ./test.exe | cat所有三个命令都会打印Greek: \xce\xb1\xce\xb2\xce\xb3\xce\xb4; German: \xc3\x9cbergr\xc3\xb6\xc3\x9fentr\xc3\xa4ger到终端。
什么不起作用:
\nx86_64-w64-mingw32-gcc -o test.exe test.cpp && wine ./test.exe这会打印Greek: \xc3\x8e\xc2\xb1\xc3\x8e\xc2\xb2\xc3\x8e\xc2\xb3\xc3\x8e\xc2\xb4; German: \xc3\x83bergr\xc3\x83\xc2\xb6\xc3\x83entr\xc3\x83\xc2\xa4ger到终端。
看起来 MinGW 运行时检测输出是否是终端/控制台,并且执行了完全错误的操作。
\n我尝试过的:
\nsystem("chcp 65001");\xe2\x80\x94 相同的输出(chcp 命令成功)。x86_64-w64-mingw32-gcc -fexec-charset=utf8 -finput-charset=utf8\xe2\x80\x94 相同的输出。SetConsoleOutputCP(CP_UTF8);\xe2\x80\x94 相同的输出。wineconsole cmd并从那里运行.\\test\xe2\x80\x94 相同的输出。LANG=en_US.UTF-8 wine ./test.exe\xe2\x80\x94 相同的输出。_setmode(_fileno(stdout), _O_U8TEXT);\xe2\x80\x94 根本没有输出。我还没有尝试过:
\n如何修复无法正常工作的情况?
\n小智 2
我查了一下,被告知wprintf()通常适用于“宽”字符格式(例如多于一个字节的字符格式)。我通常不使用 C,所以我也很好奇如何强制 UTF-8 输出。
另外,这locale.h可能会有所帮助:
// Set the console to support UTF-8 output
_setmode(_fileno(stdout), _O_U8TEXT);
Run Code Online (Sandbox Code Playgroud)