c++ new/delete and char *

前端 未结 8 994
醉梦人生
醉梦人生 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:14

    new char [strlen(s)]; does not count the closing \0 character, so your buffer is too short by one character.

提交回复
热议问题