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.
- C++ Create an empty vector
- C++ Create vector of specific size
- C++ Create vector with initial values
- C++ Copy a vector to another
- C++ Vector length or size
- 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.
- C++ Vector – Print elements
- C++ Vector – Iterate using For loop
- C++ Vector – Iterate using While loop
- C++ Vector – Foreach
- 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.
- C++ Check if vector is empty
- C++ Check if two vectors are equal
- 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.
- C++ Add element(s) to vector
- C++ Append element to the end of vector
- C++ Append vector to another vector
- C++ Insert element at the beginning of vector
- C++ Remove first element from vector
- C++ Remove last element from vector
- C++ Remove element(s) at specific index(es) from vector
- C++ Remove duplicates from a vector
- C++ Remove elements from a vector based on a condition
- C++ Resize vector
- C++ Swap elements of two vectors
- C++ Remove all elements from vector
- C++ Reverse a vector
- C++ Sort a vector
Conversions with Vectors
The following tutorials cover conversions from vector to other types, and from other types to vector.
Vector Programs
- C++ Filter even numbers in an integer vector
- C++ Filter odd numbers in an integer vector
- C++ Get unique elements of a vector
- C++ Remove empty string elements from a string vector
- C++ Sort integer vector in ascending order
- C++ Sort integer vector in descending order
- C++ Sort string vector based on length
- C++ Sort string vector lexicographically
- C++ Split vector into two equal halves