Not necessarily. If you declare a std::string
on the stack (as a local variable, say), then all of its member variables are located on the stack. Its member variables likely include a length field and a pointer to the character array. (This is up to the implementation of the standard library: the standard does not define exactly what private members a std::string
must have.)
The characters themselves are not on the stack, though. std::string
dynamically allocates its memory using new
, so the character data is on the heap.