does std::string store data differently than a char* on either stack or heap or is it just derived from char* into a class?
These solve different problems. char*
(or char const*
) points to a C style string which isn't necessarily owned by the one storing the char*
pointer. In C, because of the lack of a string type, necessarily you often use char*
as "the string type".
std::string
owns the string data it points to. So if you need to store a string somewhere in your class, chances are good you want to use std::string
or your librarie's string class instead of char*
.
On contiguity of the storage of std::string
, other people already answered.