string characteristics, length, size, capacity, string length, string size, string capacity, textual data
Time: 00:03:48 | Download:
Large,
Large (CC),
Small |
StreamingStreaming (CC) |
Slides: PDF,
PPTX
Students transitioning from Java may find it odd that C++ has two different representations for string data. Historically, strings were a primitive or fundamental data type based on character arrays and pointers. C++ inherits these fundamental strings, now called C-strings, from the C programming language. Furthermore, the first releases of C++ did not include a native string class (and creating a string class based on character arrays was, and still is, a typical example used to introduce many object-oriented programming concepts).
Today, C++ does include a full-featured string class similar to Java's String class (but take notice that in C++ the class name begins with a lower-case letter). Nevertheless, C-strings remain important for many kinds of C++ programs, so the chapter covers both C-strings and the string class. The natural progression of topics begins with arrays (covered in the previous chapter), then C-strings (a special use of character arrays), and ends with the string class.
Fundamental string characteristics.
In general, strings (C-strings and string objects) have three fundamental characteristics:
Textual data, the characters saved in the string. The string stores individual characters in an array, with one byte per character (supporting a limited number of alphabets) or two bytes per character (supporting many alphabets and additional symbols).
The length or size of a string is the number of characters it currently stores.
The capacity is the number of characters the string can hold. For C-strings, the capacity is the maximum number of characters the string can hold. However, for instances of the string class, the capacity is the maximum number of characters a specific object can hold before it must grow.