xxxxxxxxxx
vector<string> list;
list.insert(list.begin(), "Hello");
xxxxxxxxxx
Input:
vector<int> v1{ 10, 20, 30, 40, 50 };
vector<int> v2{ 100, 200, 300, 400 };
//appending elements of vector v2 to vector v1
v1.insert(v1.end(), v2.begin(), v2.end());
Output:
v1: 10 20 30 40 50 100 200 300 400
v2: 100 200 300 400
xxxxxxxxxx
#include<vector>
#include<algorithm>
// all the std and main syntax ofcourse.
vector<int> pack = {1,2,3} ;
// To add at the END
pack.push_back(6); // {1,2,3,6}
// OR
// To add at BEGGINING
pack.insert(pack.begin(),6) // {6,1,2,3,}
xxxxxxxxxx
//vector.push_back is the function. For example, if we want to add
//3 to a vector, it is just vector.push_back(3)
vector <int> vi;
vi.push_back(1); //[1]
vi.push_back(2); //[1,2]
xxxxxxxxxx
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> num {1, 2, 3, 4, 5};
cout << "Initial Vector: ";
for (const int& i : num) {
cout << i << " ";
}
num.push_back(6);
num.push_back(7);
cout << "\nUpdated Vector: ";
for (const int& i : num) {
cout << i << " ";
}
return 0;
}