How to initialize a wchar_t variable?

廉价感情. 提交于 2019-11-29 02:12:05

This works for me

#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 wc = L'\x3b1';

is the correct way to initialise a wchar_t variable to U+03B1. The L prefix is used to specify a wchar_t literal. Your code defines a char literal and that's why the compiler is warning.

The fact that you don't see the desired character when printing is down to your local environment's console settings.

try L'\x03B1' It might just solve your problem. IF you're in doubt you can try :

'\u03b1' to initialize.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!