c++ new/delete and char *

前端 未结 8 890
醉梦人生
醉梦人生 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 12:11

    You need to specify char *s1 = new char [strlen(s) + 1]; to make room for the '\0' which terminates the string.

提交回复
热议问题