From the course: C++ Templates and the STL

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Array

Array

- [ Developer] The STL array type is a fixed-size sequence container. The size of the array is defined when the array object is created. The size cannot change during the life of the array. The array object is available beginning with C++ 11. The array is designed to be fast and efficient. Although less functional than a vector, it carries no data other than its elements, and those elements are guaranteed to be stored in contiguous memory locations. Here I have a working copy of array.cpp from Chapter Two of the exercise files. The array is defined in the array header. A STL array is essentially a wrapper around a C array. So it's very fast, very efficient, and somewhat limited in what it an do. You'll see here that it's constructed very much like a vector. You can use an initializer list. You can use the default constructor and then add data later. The size function returns the size, which is always the size that the array was constructed with. If I build and run here, you'll see…

Contents