Using the dynamically allocated vector class

The Standard Library also provides the vector class in the <vector> header. Again, this class is a template, so you can use it with built-in and custom types. However, unlike array, the memory is dynamically allocated, which means that a vector can be expanded or shrunk at runtime. The items are stored contiguously so you can access the underlying buffer by calling the data function or accessing the address of the first item (to support resizing the collection, the buffer may change, so such pointers should only be used temporarily). And, of course, as with array, there is no automatic conversion to a dumb pointer. The vector class provides indexed random access with square bracket syntax and a ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.