Computer Science 1037A/B Lecture Notes - Lecture 7: Standard Template Library
Document Summary
Vectors hold a set of elements, like a one dimensional array. It is a flexible array of number elements, meaning it can grow and shrink. No need to specify size when defined, automatically adds more space as needed. Defined in the standard template library (stl), so you must include Can hold values of any type, and type is specified when a vector is defined. Stores its elements in contiguous memory locations, can use [] to access elements. Defining a vector of integers (starts with 0 elements: vector scores; Define int vector with initial size 30 elements: vector scores(30); Define 20 element int vector and initialize all elements to 0: vector scores(20,0); In this case, scores is an exact copy of finals: vector scores(finals); Use push_back(value) to add an element to a full vector or to a vector that had no defined size. Use size() member function to determine number of elements currently in a vector.