std::string
may be initialized from a C style null-terminated string (const char *
). There is no way for std::string
to know if you need that const char *
free()
d, delete[]()
d or neither, and as already stated it won't.
Use smart-pointers to automatically delete dynamically allocated objects. There are a few different of these, each specialized for particular purposes. Have a look at scoped_ptr
, auto_ptr
and shared_ptr
. Your project will probably have constraints on which smart pointers you get to use.
In the context of C++ there is never a reason to hold strings in manually declared char arrays, std::string
is much safer to use.