How to Add Multiple Elements at the End of Vector in C++? Last Updated : 01 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, vectors are dynamic arrays that can grow and reduce in size as per requirements. In this article, we will learn how to add multiple elements at the end of a vector in C++. Example Input:myVector = {10, 20, 30, 40, 50}elements_to_add = {60, 70, 80}Output:updated_vector: 10 20 30 40 50 60 70 80Insert Multiple Elements at the End of Vector in C++To add multiple elements at the end of a std::vector in C++, we can use the std::vector::insert() function provided that inserts the range containing new elements before the element at the specified position. Syntax of std::vector::insert()vectorName.insert(position, start, end);Here, position: Iterator pointing to the position which the new elements will be inserted before.start: Iterator pointing to the beginning of the range to be copied.end: Iterator pointing to the end of the range to be copied.C++ Program to Add Multiple Elements at the End of a VectorThe below example demonstrates how we can add multiple elements at the end of a vector in C++ STL. C++ // C++ program to illustrate how to add multiple elements at // the end of a vector #include <iostream> #include <vector> using namespace std; int main() { // Vector vector<int> myVector = { 10, 20, 30, 40, 50 }; // Elements to add vector<int> elements_to_add = { 60, 70, 80 }; // Print the original vector cout << "Original Vector: "; for (int i = 0; i < myVector.size(); i++) cout << myVector[i] << " "; cout << endl; // Add elements at the end of the vector myVector.insert(myVector.end(), elements_to_add.begin(), elements_to_add.end()); // Print the updated vector cout << "Updated Vector: "; for (int i = 0; i < myVector.size(); i++) cout << myVector[i] << " "; cout << endl; return 0; } OutputOriginal Vector: 10 20 30 40 50 Updated Vector: 10 20 30 40 50 60 70 80 Time Complexity: O(M), where M is the number of elements to be added.Auxiliary Space: O(M) Comment More infoAdvertise with us Next Article How to Add Multiple Elements at the End of Vector in C++? G gaurav472 Follow Improve Article Tags : C++ Programs C++ STL cpp-vector CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Add Element at the End of a Vector in C++? Vector allows fast insertion and deletion at the end. In this article, we will learn different ways to add an element at the end of the vector.The easiest way to add an element at the end of vector is by using vector push_back() function. Letâs take a look at a simple example:C++#include <bits/st 4 min read How to Add an Element at the End of List in C++? In C++, the Standard Template Library (STL) has a doubly-linked list container, known as std::list that offers various functions to manipulate elements. In this article, we will learn how to add an element at the end of a list in C++ STL. Example: Input: myList = {1, 2, 3}; Output: List after Elemen 2 min read How to Add Multiple Elements to a Set in C++? In C++, a set is a container that stores the unique elements in a sorted order. In this article, we will learn how to add multiple elements to a set in C++. For Example, Input: mySet = {1, 5, 6, 7, 8} Elements to add: {1, 2, 3, 4, 5} Output: Set Elements are: 1 2 3 4 5Insert Multiple Elements in a S 2 min read How to Insert Multiple Elements at Given Position in a Vector? In this article, we will learn how to insert multiple elements at a given index in a vector in C++.The easiest method to insert multiple elements at a specific index in a vector is by using vector insert() method. Letâs take a look at an example:C++#include <bits/stdc++.h> using namespace std; 2 min read How to Find the Average of All Elements in a Vector in C++? The average of all elements in vector is defined as the ratio of sum of all elements in vector to the number of elements in vector. In this article, we will learn how to find the average of all elements in vector in C++.The simplest method to find the average of all elements of vector is by using ac 2 min read Like