开发者

array of wchar_t

I would like to have an array of wchar_t's.

The following works:

char** stringArray;
int maxWords = 3;
stringArray = new char*[maxWords];
stringArray[0] = "I";
stringArray[1] = " Love ";
stringArray[2] = "C++"

but this does not

wchar_t ** wcAltFinalText;
wcAltFinalText = new wchar_t *[MAX_ALT_SOURCE];   // MAX_ALT_SOURCE = 4
wcAltFinalText[0] = L'\0';
wcAltFinalText[1] = L'\0';
wcAltFinalText[2] = L'\0';
wcAltFinalText[3] = L'\0';

I do not get any error but wcAltFinalText is a bad ptr

Any he开发者_如何学Pythonlp and comments are much appreciated.


You are using '' instead of "", so the assignment wcAltFinalText[0] = L'\0'; is equivalent to wcAltFinalText[0] = 0;


wcAltFinalText[0] = L'\0';

L'\0' is a wide character literal, this is an integral type - the above line corresponds to

wcAltFinalText[0] = 0;

What you want is a string literal, L"\0";


Well, you just set all elements in the newly created array to null pointers (because L'\0' is "null character", not an "empty string") - what else would you expect? You have the same effect as with this code:

wcAltFinalText[0] = 0;
wcAltFinalText[1] = 0;
wcAltFinalText[2] = 0;
wcAltFinalText[3] = 0;

and Visual Studio displays null pointers as "bad ptr" meaning no data can be behind such pointer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜