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
Now I want to delete the str object from the memory.
You can't. At least, you can't delete it completely. str is already allocated on stack (or in code segment if it is global variable), and it won't completely go away until you return from routine, leave the scope it has been created in (or until you exit the program - for global variable).
You can call .clear(), or assign empty string to it, but it doesn't guarantee that all memory will be freed. It guarantees that string length will be set to zero, but certain implementation may decide to keep part of originally allocated buffer (i.e. reserve buffer to speed up future operations, like += ).
Honestly, unless you have very small amount of available memory, I wouldn't bother. This is a very small object.