Hello, welcome to the same six tutorial in the c++ programs here with me in this talk, we're going to be looking at vectors. This is actually the last part in the series. But we do have more tutorials in general comment vectors, oftentimes for data like array and lifts, it is read cheap in terms of computing power to access elements on white lists, because you can just randomly access let's say, the value add element for vectors can grow in size on like arrays, very similar to lists, but deleting from sorry, they're minus one blacker, deleting from a vector. Depending on where you do, it can be computationally expensive. So if you do is to where that's not at the front or the back of the vectors or in the middle, it can be expensive to basically shifting the data around. But if you're just moving From the back and the front, Dan, it's okay, you're saying we've been searching as well.
So let's go ahead and open up our project. But vectors are the main data contained outside of arrays that we usually use arrays. And then if we want something that is dynamic that we can grow in size, we don't use a list. And that's our preference, we use vectors, but maybe in the future, we do different projects less may become more attractive. Okay, so what we need to do is include the built in their library and then once we've done that, we're going to create a vector, variable vector, then we specify the datatype on the int, and the name of our vector back through. And now to add data into my vector, dot push back.
I'm gonna put 45 Pm This will change some value. So the different one known. And what we're going to do is sddc out my vector to access a vector valleys very similar to an array per square bracket, the index that you want to access all the elements on one product and why semi colon and this will access technically the second element, which is that index one to start 01 so we'll print it will print 23 There we go. If we were to try and put this vector sois is for the last element is indexed free. If we were to try and perform a mountain crash or happen it will print out 45 basically loops back around so if we were to put five it will loop back round go to 23. But certainly background go to one just didn't loop back around properly on the have no idea why that didn't do that.
General rule of thumb, just access the element that you know. So basically if you've got four elements just do a 01234. And obviously you can pop elements off of it as well by doing more vector dot pop back. If I try and x run this, we get it weird. It should have popped it. Oh, you can just remember like this.
So free sign into the URL, only get there So we can access and change the element like that. They for vector if you have any questions feel free to message us at support at sound systems coda UK, the email will be in the description you can comment on this video, or just directing messages via YouTube or the recording for source code will also be in the description. I did say this in the last tutorial in the c++ program series. But that is not to say there won't be more tutorials in general, and potentially more tutorials in this series and explain what I mean by that. We have covered all the topics we want to cover. But if we, if we're just programming or whatever, for today, and we think that there's a certain topic or certain set of topics that we haven't covered in this series and deserve to be in this year.
We'll put them in basically what I'm saying if the series may grow beyond seven, six, but don't hold your breath for it. Don't wait. Don't watch the first 26 stories or the current tutorials. I think you're gonna be number one or number two, they're probably more Yep, that is it. And as usual, thank you for watching and I hope you have a great day.