assigning string::c_str() to a const char* when the string goes out of scope

后端 未结 5 1702
北恋
北恋 2021-01-18 06:22

I have a doubt on basic C++ usage. The code below, compiled with gcc/LInux, prints out correctly.

The string test goes out of scope so also its c_

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 07:08

    While the string object goes out of scope, the memory pointed to by a will still be there. I don't think the standard says anything about clearing the actual memory locations when a string is destructed.

提交回复
热议问题