Arrays are available in almost every modern programming language. But almost always, as in C++, we need to know exactly how many elements we need in the array when we create. The same is true for the array container in C++. The vector container doesn't have that limitation. So, what can we store in a vector? Anything, but every element of the vector needs to be the same data type. And the big win for us is vectors can grow and shrink as necessary as we run our code. A starting code is the code from the previous lecture. And this time we're going to convert from using the array container to using the vector container. And the big win here is that our vector container can change in size at runtime. So, we're no longer constrained to having an array of a specific size or an array container of a specific size. We can just have a vector container that grows and shrinks as needed. That also lets us have the user provide at runtime, how many scores they want to enter. And then we'll have them enter that number of scores. So, let's get started, will change this array to vector [SOUND]. We no longer have to provide a size because as I said, the vector will grow and shrink as necessary. However, we have to come up here and instead of pound including array, we need to pound include vector. And now our scores variable will be a vector container of ints. We have some work to do [SOUND]. Get how many scores [SOUND]. So will prompt for [SOUND]. And we'll tell the user what the valid range is [SOUND]. And I'll need a variable to store their answering. So, I'll just store numScores [SOUND]. So now I'm reading in how many scores they want to enter. And of course in practice we did do a while loop here to make sure that they entered a valid number. That's not the point of this lecture, so will blast past that part. So now we're going to read in the scores and I know I'm going to want a line break before I do that [SOUND]. But we can't do Scores.size at this point. We could do Scores.size but Scores.size will tell us zero right now because we haven't added anything to our vector yet. So we're going to use numScores here [SOUND] just for this one as we populate the vector. The other thing we're going to need to do is we're going to declare a variable to hold the current score that the user enters. So we're not reading into scores i anymore. We can access elements of our vector using the square bracket notation, just as we see here. But because we haven't filled up the vector yet, we'd be trying to access elements that aren't actually in the vector yet. So, I'll change all these scores i in this for loop and while loop to that variable that we have right here. [SOUND] And now, at this point right before we go back to the top of the for loop again, at this point score is a valid score. But we haven't added it to our scores vector yet. The way we do that is we say scores [SOUND] and we call the push back function. Which will put the score that we just got at the back of our vector. So, this is how we fill up the vector and add things to the vector. That's our sort of first new thing for the vector in addition to being able to dynamically say how many scores there are going to be. So now we calculate the average, again, the vector container is a range, so it has an iterator. So, we can use the range based for loop here. And it has a size function, so we can find out how many things are in the vector right now. And then we can print out everything in the vector and the average just like we've been doing. So if I run the code here, so I'm going to say I'm going to enter three scores. And now I entered the three scores [SOUND]. And as you can see it calculates the average properly and iterate over the scores properly just as we'd expect. One more thing, I want to show you, the vector container has lots of different functions we can call. As you can see we've got push back, we've got size. There's another function that you might find convenience to use periodically. So I'll say clear the scores [SOUND]. I can do this, I can take my scores vector and I can call the clearer [SOUND] function on that vector. And now if I run the code, I'll enter three scores again 1, 2, 3 and it calculates the average just fine. But the vector is now empty. So, when I get to this for loop, Scores.size is zero and zero is not less than zero. So we don't even print out any scores. So, the clear function empties the vector. And you'll find us to be really useful if you have a vector field in a class and you want to reuse that vector multiple times as your program runs. I'm going to comment this out before I give it to you. And we can see one more time That we're back to working the way we used to work. To recap, in this lecture we learned how to use a vector instead of an array or an array container, when the number of elements we need to store is likely to change.