C++ Vectors 👷🏼♂️👷🏼♀️
NOTE: ⚠ Work in progress ⚠ - Hard hats to be worn! 👷🏼♂️👷🏼♀️
#include <vector>
std::vector<int> my_ints;
Methods
at(index)
- returns the vector at 'index' - throws an exception if index is out of range.
size()
- returns the number of elements in the vector.
clear()
- clears the structure of the vector at the end.
Iterating through vectors
The C++11 method
std::vector<SomeObject> vectors;
...
for(auto item : vectors) {
// do something with item here
}
Using iterators
for(std::vector<T>::iterator it = v.begin(); it != v.end(); ++it) {
// do something with item here
}