Vectors

Learn how to use C++ vectors, a great way to keep your data organized.

Start[missing "en.views.course_landing_page.learn-c-plus-plus.course_illustration" translation]
Vectors
Lesson 1 of 1
  1. 1

    To do just about anything of interest in a program, we need a group of data to work with. For example, our program might need: - A list of Twitter’s trending tags - A set of payment options for a…

  2. 2

    The […] lives in the […] header. So first, we need to add this line of code at the top of the program: […] For review, […] is a preprocessor directive that tells the compiler to i…

  3. 3

    Now we know how to create a vector, we can also initialize a vector, giving it values, as we are creating it in the same line. For example, instead of just creating a […] vector named […] :…

  4. 4

    Now that we have a vector, how do we access an individual element? This is where index comes into play. An index refers to an element’s position within an ordered list. Vectors are 0-indexed, …

  5. 5

    Often, we start with a vector that’s either empty or a certain length. As we read or compute data we want, we can grow the vector as needed. ##### .push_back() ##### To add a new element to the “…

  6. 6

    […] not only stores the elements; it also stores the size of the vector: size The […] function returns t…

  7. 7

    So what happens when you want to change each of the values within a vector? You can use a […] loop! For example, suppose we have an […] vector that looks like this: ![1](https://i.imgur….

  8. 8

    Congratulations! You have learned about how to store groups of data into vectors in C++.  Here are some of the things that we learned: - Vectors are a sequence of elements that you can access by…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Vectors

Start[missing "en.views.course_landing_page.learn-c-plus-plus.course_illustration" translation]