我知道有人问过这个问题,我无法修复我的程序
void swap1(char*str1,char*str2)
{
char *ezer =new char[strlen(str1)];
for (int i = 0 ; i <= strlen(str1);i++)
ezer[i]=str1[i];
delete [] str1;
str1= new char[strlen(str2)];
for (int i = 0 ; i <= strlen(str2);i++)
str1[i]=str2[i];
delete [] str2;
str2= new char[strlen(ezer)];
for (int i = 0 ; i <= strlen(ezer);i++)
str2[i]=ezer[i];
delete[] ezer;
}
一次第一次在第二次(有其他值)工作时出现错误,错误出现在最后一行delete[] ezer;
,为什么我不能删除ezer
?
错误:
heap corruption detected after normal block (#174) at 0x007D7A48
CRT detected that the application wrote to memory end of heap buffer