Recently i have the problem with c_str().below is the sample code snippet
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
class har{
    public:
    string h;
    har(string str){
        h=str;
    }
};
int main(){
har *hg=new har("harish");
const char *ptr=hg->h.c_str();
delete hg;
cout<<ptr<<endl;
return 0;
}
I am getting the output as "harish"....I have destroyed the object but still i am getting the output..is c_str() again allocating memory in heap.
 
     
    