"Alfonso Morra" <sw***********@the-ring.com> wrote in message news:dh**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Hi,
Doest the c_str() method of the string class allocate memory. if it does
alloc mem behind the scenes - whose responsibility is it to cleanup
after (i.e. free the returned char*?)
Tkx
That's up to the compiler author.
You don't need to worry about allocation or deallocation;
that's all handled for you automatically.
Some warnings about c_str() :
If you do something like this:
std::string Catz = "Round and round she goes!";
const char* Batz = Catz.c_str();
Then Batz is a pointer to an object which is owned by the
std::string object Catz. This means you need to remember
these two things:
1. You can NOT write to the location pointed to by Batz!
It's read-only. In fact, a good compiler won't even
let you omit the "const" in the definition of Batz above.
2. If Catz goes out of scope, Batz is no-longer guaranteed
to point to anything useful. Dereferencing Batz at that
point might crash your program (or your system).
Cheers,
Robbie Hatley
Tustin, CA, USA
email: lonewolfintj at pacbell dot net
web: home dot pacbell dot net slant earnur slant