In this C++ tutorial, we will go through some of the most used Vector Operations with examples.

C++ Vector Operations

Vectors are containers that can store elements in order, and can change in size.

We can perform operations on C++ Vector, like CRUD operations, conversions from vector to other datatypes or vice versa, etc.


Creating Vectors

The following list of tutorials cover scenarios of how to create a vector.

  1. C++ Create an empty vector
  2. C++ Create vector of specific size
  3. C++ Create vector with initial values
  4. C++ Copy a vector to another
  5. C++ Vector length or size
  6. C++ Vector of vectors

Accessing Vectors and their Elements

We can access the elements of a vector. The following tutorials show how to access elements using an index, or iterate in a loop, etc.

  1. C++ Vector – Print elements
  2. C++ Vector – Iterate using For loop
  3. C++ Vector – Iterate using While loop
  4. C++ Vector – Foreach
  5. C++ Vector – Get reference to element at specific index

Checks on Vectors

The following tutorials cover different checks that we can make on a vector.

  1. C++ Check if vector is empty
  2. C++ Check if two vectors are equal
  3. C++ Check if element is present in vector

Update or Transform Vectors

The following tutorials cover update or remove operations at element level on a vector.

  1. C++ Add element(s) to vector
  2. C++ Append element to the end of vector
  3. C++ Append vector to another vector
  4. C++ Insert element at the beginning of vector
  5. C++ Remove first element from vector
  6. C++ Remove last element from vector
  7. C++ Remove element(s) at specific index(es) from vector
  8. C++ Remove duplicates from a vector
  9. C++ Remove elements from a vector based on a condition
  10. C++ Resize vector
  11. C++ Swap elements of two vectors
  12. C++ Remove all elements from vector
  13. C++ Reverse a vector
  14. C++ Sort a vector

Conversions with Vectors

The following tutorials cover conversions from vector to other types, and from other types to vector.

  1. C++ Convert array to vector
  2. C++ Convert vector to map
  3. C++ Join elements of vector to a string

Vector Programs

  1. C++ Filter even numbers in an integer vector
  2. C++ Filter odd numbers in an integer vector
  3. C++ Get unique elements of a vector
  4. C++ Remove empty string elements from a string vector
  5. C++ Sort integer vector in ascending order
  6. C++ Sort integer vector in descending order
  7. C++ Sort string vector based on length
  8. C++ Sort string vector lexicographically
  9. C++ Split vector into two equal halves