Vectors
Learn how to use C++ vectors, a great way to keep your data organized.
StartKey Concepts
Review core concepts you need to learn to master this subject
Vector Type
Vector Type
During the creation of a C++ vector, the data type of its elements must be specified. Once the vector is created, the type cannot be changed.
Vectors
Lesson 1 of 1
- 1To 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…
- 2The std::vector lives in the header. So first, we need to add this line of code at the top of the program: #include For review, #include is a preprocessor directive that tells the compiler t…
- 3Now 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 double vector named location:…
- 5Often, 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 “…
- 7So what happens when you want to change each of the values within a vector? You can use a for loop! For example, suppose we have an int vector that looks like this: ![1](https://content.codecade…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory