Contents
In addition to the built-in types covered in Chapter 2, C++ defines a rich library of abstract data types. Among the most important library types are string
, which supports variable-length character strings, and vector
, which defines variable-size collections. Associated with string
and vector
are companion types known as iterators, which are used to access the characters in a string
or the elements in a vector
.
The string
and vector
types defined by the library are abstractions of the more primitive built-in array type. This chapter covers arrays and introduces the library vector
and string
types.
The built-in types that we covered in Chapter 2 are defined directly by the C++ language. These types represent facilities present in most computer hardware, such as numbers or characters. The standard library defines a number of additional types of a higher-level nature that computer hardware usually does not implement directly.
In this chapter, we’ll introduce two of the most important library types: string
and vector
. A string
is a variable-length sequence of characters. A vector
holds a variable-length sequence of objects of a given type. We’ll also cover the built-in array type. Like other built-in types, arrays represent facilities of the hardware. As a result, arrays are less convenient to use than the library string
and vector
types.
Before beginning our exploration of the library types, we’ll look at a mechanism for simplifying access to the names defined in the library.