How to properly free a std::string from memory

后端 未结 6 769
余生分开走
余生分开走 2021-01-30 05:35

What\'s the best way to delete an std::string from memory allocated on the heap when I\'m done using it? Thanks!

6条回答
  •  自闭症患者
    2021-01-30 05:42

    std::string foo("since it's on the stack, it will auto delete out of scope");
    

    or:

    std::string* foo = new std::string("allocated on the heap needs explicit destruction")
    delete foo;
    

提交回复
热议问题