
In this section, we'll go over the different ways of initializing a vector in C++. Note that you must put include at the top of your file to be able to use vectors.

Lastly, the vector name - we can call this whatever we want. This is followed by angle brackets which contain the the type of data the vector can accept like strings, integers, and so on. Unlike arrays in C++ where the memory allocated to the collection is static, vectors let us create more dynamic data structures.Įvery new vector must be declared starting with the vector keyword. While these data structures have their distinctive features, we'll focus mainly on the various methods of initializing vectors.īefore that, let's talk briefly about vectors and what makes them stand out when dealing with data collections in C++. In C++, you can store them in arrays, structures, vectors, strings and so on.


When you're working with a collection of variables or data in programming, you usually store them in specific data types.
