In this chapter we explore different ways to create a string and manage string buffer data. It is helpful to remember from chapter 3 that a string is composed of two parts: a structure that contains a length and data field, and the data itself. The string's main structure can exist on the stack, on the heap or as a global variable. The data portion of a string can exist in any of these same places or not at all. Also, a string can dynamically relocate its data buffer to allow for string expansion and prevent buffer overruns.
I'll assume that you are familiar with how to create the string structure on the stack, heap, or as a global variable since this capability is a basic feature of C/C++. To create the string data itself in one of the three places, you can choose from a number of construction functions described below.