This is about creating and using vectors in C++. A vector in c++, is used to store different values in different storage compartments. It works almost the same as an array, the only difference is that the storage space can change. This is one of the differences with the arrays that storage spaces have to be declared.

 

Vectors take more memory space than arrays do. It is a list of values in which each of them are identified with a number. They can be made by any element and type.

These is how you declare a vector.

 

       You declare de type inside the angle brackets.

       You can declare the size of your vector in between parenthesis ( 6).

   

             Vectors can be represented in the same way as arrays, like in a table.

       The count of vectors starts in 0.

 

Now you have located your values inside vectors, how can you access them? It is using the [ ]. You can give some space a value like this:

 

count[4]= 60;

 

The best part of using them is that its size can be modified.

 

           The copy constructor takes one vector and copies it in the same size.

 

   –       You can involve functions with a vector, like size( ). This function gives the size of a vector.

 

Vectors can also be used to create random numbers. Computers are designed to always return back any result with the same process, this is a problem when you are looking for the computer to show up a random number. C++ has a function called random that does all this process for you.

 

It is important to learn how to make use of the different facilities c++ have for you. You just need to be very careful when using them.

 

WATCH MY VIDEO https://youtu.be/XRxkoby_RUE

CC BY 4.0 #Mastery23 – Creation and use of vectors in C++ by Ricardo Newton is licensed under a Creative Commons Attribution 4.0 International License.