How to initialize a wchar_t variable?

前端 未结 3 1941
你的背包
你的背包 2020-12-31 12:59

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:

<         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 13:52

    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.

提交回复
热议问题