c++ new/delete and char *

前端 未结 8 905
醉梦人生
醉梦人生 2021-02-02 11:50

Can anyone help me, why I\'m getting an error message while trying to free the allocated memory: Heap corruption detected. CTR detected the application wrote the memory after en

8条回答
  •  抹茶落季
    2021-02-02 11:56

    You've corrupted s2 pointer by

    strcpy(s, "hello");
    

    Because s has size 5, while you've missed that strcpy includes string terminator.

提交回复
热议问题