printf()无法输出wchar_t类型字符的问题求助
问题:printf无法输出wchar_t类型字符
尝试了多种方法,但printf()始终无法输出wchar_t类型的字符,没有任何内容被打印出来。
初始尝试代码:
#include <stdio.h> #include <locale.h> #include <wchar.h> int main(void) { setlocale(LC_ALL,""); wchar_t a = 0xfe; printf("%lc",a); return 0; }
后续尝试的多种修改版本,均无效:
版本1:
int main(void) { setlocale(LC_ALL,""); wchar_t a = '\u00FE'; printf("%lc",a); return 0; }
版本2:
int main(void) { setlocale(LC_ALL,""); wchar_t a = '\U000000FE'; printf("%lc",a); return 0; }
版本3:
int main(void) { setlocale(LC_ALL,""); wchar_t a = 0xfe; wchar_t* b = &a; printf("%ls",b); return 0; }
版本4:
int main(void) { setlocale(LC_ALL,""); wchar_t* b = L"\u00FE"; printf("%ls",b); return 0; }
版本5:
int main(void) { setlocale(LC_ALL,""); wchar_t a = 0xfe; printf("%C",a); return 0; }
只有直接使用以下代码能正常输出,但我需要将字符存入变量中使用:
printf("\u00FE");
另外,VSCode的提示框中能显示thorn字符,但程序运行时却无法输出。
环境:Windows 10、VSCode(仅安装C/C++扩展包)、MinGW GCC编译器
内容的提问来源于stack exchange,提问作者Bfyuvf
相关产品推荐
相关产品推荐

