-
Notifications
You must be signed in to change notification settings - Fork 0
Vector
KROIA edited this page May 22, 2018
·
7 revisions
- Constructor
- size predefined a size of the Array
Vector<int> myVector;
Vector<String> myVector;
- You can choose any type as a Vector
- Deletes all saved data in the array.
delete &myVector;
- Adds an element to the array.
myVector.push_back(15);
- Returns the last last element of the array.
- Deletes the last element in the array.
- Decreses the size of the array.
int value = myVector.pop_back();
- Gets the size of the array.
unsigned int size = myVector.size();
- Resizes the array.
- Used to make the push_back() faster.
- Reservs storage for size elements.
- returns the actual size of the array which is reserved in storage.
Vector<int> myVector;
myVector.resize(5);
myVector.size() == 0
myVector.capacity() == 5
- When an element is pushed back the size won't increase until capacity <= size.
myVector.push_back(1);
myVector.size() == 1
myVector.capacity() == 5
- Erase a sequence of elements in the array.
- Beginning from element pos.
- From there on deletes amount elements.
-
myVector.erase(2,3);
Erases the elements: [-]: [x][x][-][-][-][x][x] -
myVector.erase(2);
Erases the element: [-]: [x][x][-][x][x][x][x]
- Clears the whole array.
- All elements get deleted.
myVector.clear();
- Gets the pointer of the first element in the array.
-
Don't use it in
myVector.erase(myVector.begin());
int *p_int = myVector.begin();
Wiki
Arduino libraries