// Native_Vectors.cpp : Defines the entry point for the console application. /*______________________________________________________________ W O R K I N G W I T H V E C T O R S Ron Kessler Created 1/7/2017 Native version Run with CTL-F5 When using a Vector you are basically using a resizable array! You do not need to define its size. When you add elements, they are added to the end automatically. You can delete the last element and also use the std::sort algorithm. To see each feature, put your cursor on the line past the feature you want and rt. click and choose Run to Cursor. Then hover over ages to see the effect of each feature. Uncomment each one you want to examine. */ #include "stdafx.h" #include #include #include //so we can sort using namespace std; int main() { //---create a vector of integers vector ages{ 14, 33, 24, 53, 20 }; //the size is determined by the elements in {} int numElements = ages.size (); //***************add new item to vector**************** //ages.push_back (55); //ages.push_back (36); //************now change a value of one of the elements************* //Lets make element 0 which was 14, 90. //ages[0] = 90; //could also do ages[0]++ to increment it. //*************delete last element************* //ages.pop_back (); //************now lets sort the vector*********** //sort (ages.begin (), ages.end ()); //*************Iterate over the vector to view contents************* cout << "This shows the current values in your vector: \n\n"; for (unsigned int x = 0; x < ages.size (); x++) { cout << ages [x] << "\n"; } return 0; }