Well, acutally, the string was "char[255]" (I used it to read from a file using fgets and since the string's length can't be determined, I used 255). And the problem still occur.

Quote Originally Posted by siavoshkc
First: What is the [] in front of delete?
Second: strlen("Hello world!") == 13 not 12. You should give it an additional byte for '\0' == NULL that indicates the end of the string in the memory. Its better to write
Code:
char *foo;
char foo2[]="Hello world!";

foo=new char[strlen(foo2)];
strcpy(foo,foo2);
delete foo;