Visual c++ 来自char[]的CString构造函数

Visual c++ 来自char[]的CString构造函数,visual-c++,Visual C++,从char[]构造CString好吗 char R[5000]; CString s = R; 在这些行中,有时我有例外: Windows has triggered a breakpoint in tst.exe. This may be due to a corruption of the heap, which indicates a bug in tst.exe or any of the DLLs it has loaded. This may also be due to th

从char[]构造CString好吗

char R[5000];
CString s = R;
在这些行中,有时我有例外:

Windows has triggered a breakpoint in tst.exe.

This may be due to a corruption of the heap, which indicates a bug in tst.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while tst.exe has focus.

The output window may have more diagnostic information

CString
构造函数尝试从输入参数(更准确地说,从输入参数指向的内存地址)复制以null结尾的字符串

因此,它复制字符直到达到0(null)字符,并且由于
R[5000]
的内容没有初始化,因此很有可能其中没有一个字符等于0


如果输入参数所指向的合法内存区域内没有此类字符,则
CString
构造函数超出了该内存区域,很可能导致非法内存访问。

此代码的意义是什么?为什么要用垃圾数据初始化
CString
对象?是的,这很好。当
char[]
包含以零结尾的字符串时。