T
- Type of elements.
Return: none
Arguments: T
Adds an element to the back.
Return: T
Arguments: unsigned int
Access specified element.
Return: unsigned int
Arguments: none
Returns the number of elements.
Return: bool
Arguments: none
Returns whether the vector is empty.
Return: iterator
Arguments: none
Returns an iterator to the begining.
Return: iterator
Arguments: none
Returns an iterator to the end.
Library include
#include "path/to/Basic-Data-Structures/include/vector"
Vector declaration
Vector<int> v;
Basic push_back
and operator[]
usage
v.push_back(3); // vector: 3
v.push_back(7); // vector: 3 7
v.push_back(-2); // vector: 3 7 -2
v[1] = 4; // vector: 3 4 -2
std::cout << v[2] << "\n"; // prints -2
std::cout << v[1] << "\n"; // prints 4
Print vector using size
and operator[]
for(int i = 0; i < v.size(); i++) {
std::cout << v[i] << "\n";
}
Print vector using iterator
with range-based for loop
and auto
(C++11)
for(auto i : v) {
std::cout << i << "\n";
}