请问:为什么delete的时候出问题了?
isaxu 2003-01-22 07:41:51 #include<stdafx.h>
#include<iostream.h>
char * strcpy(char* dest,const char* source);
void main()
{
char* a = new char;
cout<<"input a:"<<endl;
cin>>a;
char* b = new char;
cout<<"the end is "<<strcpy(b,a);
cout<<"after copy, a is:"<<a<<endl;
cout<<"after copy, b is:"<<b<<endl;
delete b; //如果加上这两个delete,就会出错,可是,书上不是说要释放空间嘛?
delete a;
}
char * strcpy(char* dest,const char* source)
{
char *tmp = new char;
tmp = dest;
while((*source)!='\0')
{
*dest = *source;
source++;
dest++;
}
dest = tmp;
cout<<"dest is "<<dest<<endl;
return dest;
}