If I try to delete a char I get an access violation error.
Heres my code:
int main()
{
char *myString = new char[32];
myString = "Hello";
cout << myString;
cin.get();
delete [] myString;
return 0;
}
Ive also tried
delete myString
but im still get access violation errors
After the line
the pointer
myStringno longer points to the array you’ve allocated, but to a string literal. The linethen attempts to delete the literal (which results in a crash).
You can copy a string with
strcpy, or better yet, usestd::string.