delete[] assert error

I am getting an assert error for a delete[] statement that only usually happens to me when i accidently try to delete it twice or something.
But can anyone tell me why this code also gives me an assert error in ms vc++?
1
2
3
4
5
int main ()
{
    char* title = new char[11] = "123456789\0";
    delete[] title;
}


thanks
I think you should break your line in two:
1
2
3
4
5
6
7
8
9
10

int main()
{

    char* title = new char[11];
    title = "123456789\0";
    delete[] title;

    return 0;
}
Same error, both forms are equivalent.
I do not get any error...
Here's what I'm getting: http://i35.tinypic.com/14dlyzm.jpg
So far I've been able to reproduce this error on two different computers, one with the latest Visual Studio and one with the Express edition.
Last edited on
Yeah, got the error: title = "123456789\0"; is pointing title to a new location, this should run on VC++:
1
2
3
4
5
6
7
8
9
10
int main()
{

    char *title = new char[11], value[11]="123456789\0";
    for (short p=0; p<11; p++)
          title[p]=value[p];
    delete[] title;

    return 0;
}
Last edited on
in dev-c++ or borland c it works jusr fine.....so u might create an app for c++ (or ANSI c).....at least .....it should work ;)
Bazzy's last code worked.
I guess '= "123456789/0" ' returns a pointer, ie. it is not a copy operator.
Thanks Bazzy.
IMO.

1
2
3
4
5
6
7
8
9
int main()
{

    char* title = new char[11];
    sprintf(title, "%s", "123456789");
    delete[] title;

    return 0;
}
Topic archived. No new replies allowed.