A template type is a special type in C++ that can take on different types whenever the type is initialized. For example, the standard vector is a template type. What that means is, in the standard vector, we can have a vector of characters, for example the word Illinois; a vector of integers, for example, the first few prime numbers; or even a vector of UIUC cubes are custom data type. All of these things represents a array of objects in memory, and it's done through a standard single library called the vector. The standard vector or std::vector is part of the standard template library we discussed earlier. It provides the functionality of a dynamically growing array with a templated type. So, there's five key ideas of how we're going to use this vector. The first is we're going to include the vector in our program by using #include <vector>. That's going to add the ability for us to use the standard vector into that source code file. We initialize a vector by saying std::vector and we give it the templated type inside of these alligator braces. For example, on the previous slide, we saw inside these alligator braces was character, was int, and was UIUC cube. Once we have a vector initialized, there's three functions that we're going to run on this vector. The first is to run the function push back and then add an element to the back of the array. Our syntax would be something like v.push_back(4). This pushes back the number four onto the vector. The second function is the array operator bracket. So, for example, we might want to access the first element in our vector. We would say v[0], since v was declared vector and we want to access element zero. This v[0] is going to retrieve us the zeroth element in the vector, so that is going to be the thing that we just added if we've only added one element to the vector. The last thing we can do is we can say v.size which asked the vector what it's size is. As we mentioned earlier, when initializing a templated type, the template goes inside of the alligator brackets at the end of the name. So, for example, the name of the object we're initializing is a standard vector, and we use these alligator brackets the int. So, this is standard vector of characters. We can go ahead and see this in source code. So, here's a simple program that just uses both the vector and the iostream library. We've included both of these libraries and then here on line 11, we have our main. Now, on line 12, we initialize a new vector that's going to store integers. So, we're creating a vector. This vector stores integers, and because vectors are dynamically growing arrays, if it runs out of space, it's going to make it larger. I'm going to draw it exactly how large it needs but we're not exactly sure what the capacity of that vector is. Next week, we're going to actually explore some detail analysis to understand what the optimal size of a vector might be. Here, we're going to push two to the end of the vector. So, here, we're adding two to the vector, three were pushing three to the back of the vector, and five to the back of the vector here. Then, on line 17, we're going to see out v[0]. So, we're going to look at our vector and look at what's in index 0 and print that to the screen. So, in index 0, we're going to see two print note, index 1 is here containing element 3, and index 2 contains the element 5 and 5. So, when we run this program, we expect our output screened to be 2, 3, 5. Let's head over to the console and see what happens. I'm going to move into the CPP vector directory and then move into the example one directory and run make to build this program, then run./main to run it. Here, we see the output of 2, 3,,5; exactly what we expected. Let's go and look at the second example. Here's the source code for example 2. We see the same thing that we're including vector and iostream as the two libraries we're going to use. So, what we know is we're probably going to be using a vector to store some data and we're going to use cout to output data to the console from the iostream library. Here on line 11, we find our main. Line 12, we initialize a new vector. This vector is going to contain a lot of objects because we have a four loop here that loops from 0-100 and we're going to push back the square of whatever i is. So, the first time this four loop runs, i is going to be 0. I'm going to push in 0 times 0 to the vector, so the first element in the vector is going to be zero. Second time the loop runs, i equals 1. I'm going to push and 1 times 1 to the vector, so the second element in the vector is 1. Third time we run through a loop, i is equal to 2. Element in the vector is 2 times 2, so four goes into the vector here. When i is equal to 3, we're going to put 3 times 3 or i times the vector. That's going to put 9 into the vector, then 16, then 25 and so on. So, each element of the vector up until the 99th index is going to contain the square of its index. Note that here is index 0 that contains element 0. Here's index 1 that contains 1 squared or 1. Here's element index 2 that contains 2 squared to four and so forth. Now, on line 17, we can predict what's going to happen when we cout v[12]. V[12] is going to look at index 12. We know that the value contained in v[12] is going to be square of its index. So, looking at 12 times 12 that's going to be equal to 144. So, we expect the output of v[12] to be 144 because v[12] is going to be placed into the vector by pushing it back when i is equal to 12. Let's go ahead and see if this matched up when we run our code. Here in the console moving out of the example 1 directory moving into the example 2 directory running make and./main. Here we see the output is indeed 144. So, what you've seen here is we now have an ability to create an array like structure inside C++ called a vector. The vector is slightly different than an array that you may be familiar with in the sense that it grows dynamically. We don't care about its capacity because the capacity is going to grow and shrink as needed. In the next video, we're going to explore a program that makes use of vectors and all the things we know about to build something really awesome. So, I'll see you there.