Unicode string literals in C# vs C++/CLI

前端 未结 2 1138
你的背包
你的背包 2021-01-27 02:40
C#:
char z = \'\\u201D\';
int i = (int)z;

C++/CLI:
wchar_t z = \'\\u201D\';
int i = (int)z;

In C# \"i\" becomes, just as I expect, 8221 (

相关标签:
2条回答
  • 2021-01-27 02:56

    According to wikipedia:

    "The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers."

    You shouldn't make any assumptions about how it's implemented.

    0 讨论(0)
  • 2021-01-27 03:15

    You want:

    wchar_t z = L'\x201D';
    

    from here. \u is undefined.

    0 讨论(0)
提交回复
热议问题