C++ strings and pointers

This is because you have not allocate your objects prior to using them:

string * firstName = new string();
//...
delete firstName;

It’s worth adding that using pointers in this situation is, well, pointless: string objects in the standard C++ library allocate the data for the string from the heap; strings are usually not much more than a pair of pointers anyway.

Leave a Comment