+ 17
Vectors are sequence structures representing arrays that are dynamic in size, i.e. Their size can be specified and altered even at runtime...
Thus unlike arrays, you need not give them a size before...
They also use contiguous storage locations, and the elements are accessible using offsets on pointers or iterators...
Since they are dynamic in nature, they use slightly more memory...
The C++ STL Library contains an entire template specified class for vectors, which contains predefined methods and overloads of operators and functions...
Some include:
resize() - resize the vector to a new size...
push_back() - insert element at the end...
at() or operator[] - access a particular element...
size() - current size is returned...
pop_back() - remove an element...
Read more here:
www.cplusplus.com/reference/vector/vector
#include<vector> must be included in your program...
Eg-
vector<int>vec(4,100)
//4 integers of value = 100)
vector<int>::iterator it=vec[1];
vec.push_back(200);
//Now has 5 ints with last one 200
if(!vec.empty)
{
vec.erase(1);
// Now has 4 ints, 3 100 and last one 200
vec.resize(5);
// Resized to 5
}
vec.insert(it,300);
//Inserts 300 at 1
//Thus now vec contains 100 300 100 200 0...



