简体   繁体   中英

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 help 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM