wchar_t 数组
我想要一个 wchar_t 数组。
以下有效:
char** stringArray;
int maxWords = 3;
stringArray = new char*[maxWords];
stringArray[0] = "I";
stringArray[1] = " Love ";
stringArray[2] = "C++"
但这不是
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';
我没有收到任何错误,但 wcAltFinalText 是一个坏 ptr
非常感谢任何帮助和评论。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您使用的是
''
而不是""
,因此赋值wcAltFinalText[0] = L'\0';
相当于wcAltFinalText[0] = 0;
You are using
''
instead of""
, so the assignmentwcAltFinalText[0] = L'\0';
is equivalent towcAltFinalText[0] = 0;
L'\0'
是一个宽字符文字,这是一个整数类型 - 上面的行对应于What you Want is a string 文字,
L"\ 0";
L'\0'
is a wide character literal, this is an integral type - the above line corresponds toWhat you want is a string literal,
L"\0";
好吧,您只需将新创建的数组中的所有元素设置为空指针(因为
L'\0'
是“空字符”,而不是“空字符串”) - 您还期望什么?您将获得与此代码相同的效果:并且 Visual Studio 将空指针显示为“bad ptr”,这意味着此类指针后面不能有任何数据。
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:and Visual Studio displays null pointers as "bad ptr" meaning no data can be behind such pointer.