I have a method that requires a const char pointer as input (not null terminated). This is a requirement of a library (TinyXML) I’m using in my project. I get the input for this method from a string.c_str() method call.
Does this char pointer need to be deleted? The string goes out of scope immediately after the call completes; so the string should delete it with its destructor call, correct?
The char array returned by
string.c_str()is null terminated.If tinyXML’s function takes a not null terminated char* buffer, then your probably gonna get some unexpected behaviour.No, it does not need to be released. String’s destructor does that for you.
Source