Deleting string object in C++

前端 未结 4 1311
挽巷
挽巷 2021-01-18 00:19

I have a string object in my C++ program declared as follows:

string str;

I have copied some data into it and done some operations. Now I w

4条回答
  •  无人及你
    2021-01-18 01:00

    You don't have to. When the string goes out of scope, it's destructor will be called automatically and the memory will be freed.

    If you want to clear the string right now (without waiting until it goes out of scope) just use str.clear().

提交回复
热议问题