C++ Vectors

Vectors contain contiguous elements stored as an array.

Accessing members of a vector can be done in constant time, appending elements to a vector can be done in amortized constant time, whereas locating a specific value or inserting elements into the vector takes linear time.

Constructorscreate vectors and initialize them with some data
Operatorscompare, assign, and access elements of a vector
assignassign elements to a vector
atreturn a reference to an element at a specific location
backreturns a reference to last element of a vector
beginreturns an iterator to the beginning of the vector
capacityreturns the number of elements that the vector can hold
clearremoves all elements from the vector
emptytrue if the vector has no elements
endreturns an iterator just past the last element of a vector
eraseremoves elements from a vector
frontreturns a reference to the first element of a vector
insertinserts elements into the vector
max_sizereturns the maximum number of elements that the vector can hold
pop_backremoves the last element of a vector
push_backadd an element to the end of the vector
rbeginreturns a reverse_iterator to the end of the vector
rendreturns a reverse_iterator just past the beginning of the vector
reservesets the minimum capacity of the vector
resizechange the size of the vector
sizereturns the number of items in the vector
swapswap the contents of this vector with another

Notes:

Note that a boolean vector (vector<bool>) is a specialization of the vector template that is designed to use less memory. A normal boolean variable usually uses 1-4 bytes of memory, but a boolean vector should use only one bit per boolean value.