开发者

Terminating unicode null character

I have an array of wchar_t. I need to add a unicode null character at a specific position in the array.

wchar_t var1[100];

var1[79] = '\开发者_运维知识库u0000';

I tried the above but get the following compilation error.

error C3850: '\u0000': a universal-character-name specifies an invalid character

How do I add a unicode null character?


I think you can use

var1[79] = L'\0'


The language doesn't allow you to use universal character names for characters that you can easily write without using a UCN. That's why '\u0000' isn't permitted. (I'm not quite sure what the rationale for that rule is.)

Since var1 is an array of wchar_t, L'\0' is the most straightforward thing to use.

But since char, wchar_t, and int are all integral types, and since values of any integral type can be assigned to an object of another integral type (as long as the value is in range of the target type), any of the following will work:

var1[79] = L'\0'; // best
var1[79] = '\0';  // char value converted to wchar_t
var1[79] = 0;     // int value converted to wchar_t


I have programmed some simple window applications using raw api32 and my best guess is to use L'\0'.


Integer zero will also do:

var1[79] = 0;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜