#include <iostream>
using namespace std;
char *CopyOf(const char *str);
void main(void)
{
char *hello = CopyOf("Hello\n");
cout << hello;
delete [] hello;
system("pause");
}
char *CopyOf(const char *str)
{
char *copy = new char(strlen(str) + 1);
strcpy(copy, str);
return copy;
}
Run Code Online (Sandbox Code Playgroud)
程序运行到delete语句时发生我的错误.有什么建议吗?非常感谢你.