Vector <int> intVector;
int arrayOfInts[11]; // declares an array of ints with 11 positions
void setup() {
Serial.begin(9600);
pinMode(48, OUTPUT); // turn ON wiring hardware LED
digitalWrite(48, HIGH);
for(int i=0; i<10; i++) { // add 255 elements from 0 to 254
intVector.addElement(i);
}
intVector.copyInto(arrayOfInts); // copy the Vector content into an array
Serial.print("The arrayOfInts elements are: ");
for(int i=0; i<10; i++) { // print all all elements in the array
Serial.print(arrayOfInts[i], DEC);
Serial.print(" ");
}
Serial.println();
Serial.print("The vector's capacity is: ");
Serial.println(intVector.capacity(), DEC); // print the vector's capacity
intVector.ensureCapacity(20);
Serial.print("now the vector's capacity is: ");
Serial.println(intVector.capacity(), DEC); // print the vector's capacity
Serial.print("The vector's size is: ");
Serial.println(intVector.size(), DEC); // print the vector's size
intVector.setSize(5);
Serial.print("now the vector's size is: ");
Serial.println(intVector.size(), DEC); // print the vector's size
Serial.print("The vector's capacity is: ");
Serial.println(intVector.capacity(), DEC); // print the vector's capacity
intVector.trimToSize();
Serial.print("now the vector's capacity is: ");
Serial.println(intVector.capacity(), DEC); // print the vector's capacity
}
void loop() {
}
|