堆内存数组操作问题?
我用Wizard创建了一个支持MFC的Win32 Console Application,程序代码如下:CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
char* c=new char[6];
strcpy(c,(const char*)"111");
char* d = "sss";
strcat(c,d);
printf("the string is %s\n", c);
delete []c; // 程序运行到这里crash,为什么?
c = NULL;
}
return nRetCode;
}