vectors in c++
Declaration of vector:
std::vector<int> v;
Adding elements to the vector:
v.push_back(3);
v.push_back(7);
Accessing elements of the vector:
int firstElement = v[0];
int secondElement = v[1];
Size of the vector:
int size = v.size();
Iterating through the vector using a for loop:
for (int i = 0; i < v.size(); i++) {
std::cout << v[i] << " ";
}
Iterating through the vector using a range-based for loop (C++11 onwards):
for (auto element : v) {
std::cout << element << " ";
}