Creation and use of vectors.

First you need to call the vector library:

Screen Shot 2015-11-25 at 01.47.22

As usual this will allow us to form vectors and use their properties.

In this example we will make use of vectors to create a list of integers and returns the sume of the squares of the elements in the list.

We create our function specifying that we’ll be using a vector.Screen Shot 2015-11-25 at 01.53.06

It’s important to define the name of the vector in this case “x” and the category of it, in this case “int” (Integers).

Then, on our main function, we will add all the specifications for the vector in this case we will specify it’s length and the values assigned to every component of the list.

Screen Shot 2015-11-25 at 01.55.36

And that’s and easy example of how to use vectors in C++

CC BY 4.0 Mastery 23 by Luis Daniel García is licensed under a Creative Commons Attribution 4.0 International License.