如何初始化wchar_t变量? [英] How to initialize a wchar_t variable?

查看:2653
本文介绍了如何初始化wchar_t变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读这本书: C:In a Nutshell ,并且在阅读关于宽字符的字符集部分之后,我编写了这个程序: p>

I am reading the book: C: In a Nutshell, and after reading the section Character Sets, which talks about wide characters, I wrote this program:

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

int main() {
  wchar_t wc = '\x3b1';
  wprintf(L"%lc\n", wc);
  return 0;
}

然后我使用gcc编译它,但是gcc给了我这个警告:
$ b

I then compiled it using gcc, but gcc gave me this warning:


main.c:7:15:警告:十六进制转义序列超出范围[默认情况下启用]

main.c:7:15: warning: hex escape sequence out of range [enabled by default]

该程序不会输出字符α(其Unicode编码为U + 03B1),这正是我想要的。

And the program does not output the character α (whose unicode is U+03B1), which is what I wanted it to do.

如何更改程序打印字符α?

How do I change the program to print the character α?

推荐答案

这适用于我

#include <stdio.h>
#include <stddef.h>
#include <wchar.h>
#include <locale.h>

int main(void) {
  wchar_t wc = L'\x3b1';

  setlocale(LC_ALL, "en_US.UTF-8");
  wprintf(L"%lc\n", wc);
  return 0;
}

这篇关于如何初始化wchar_t变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆