In today's class, among many topics we discussed vectors. Vectors are like arrays that can change size as your program runs.
To declare a vector:
vector <int> v;
To access vector elements:
v[i] = 45;
cout << v[i];
To initialize vector elements we use the member function push-back. This adds the element in the next available position.
Don't forget to include the vector library!!
#include <vector>
No comments:
Post a Comment