1// CPP program to create an empty vector
2// and push values one by one.
3#include <vector>
4
5using namespace std;
6int main()
7{
8 // Create an empty vector
9 vector<int> vect;
10 //add/push an integer to the end of the vector
11 vect.push_back(10);
12 //to traverse and print the vector from start to finish
13 for (int x : vect)
14 cout << x << " ";
15
16 return 0;
17}
1#include <iostream>
2#include <vector>
3
4#define M 3
5#define N 4
6
7int main()
8{
9 // specify default value to fill the vector elements
10 int default_value = 1;
11 // first initialize a vector of ints with given default value
12 std::vector<int> v(N, default_value);
13 // Use above vector to initialize the two-dimensional vector
14 std::vector<std::vector<int>> matrix(M, v);
15
16 return 0;
17}
18
1vector<int> a; // empty vector of ints
2vector<int> b (5, 10); // five ints with value 10
3vector<int> c (b.begin(),b.end()); // iterating through second
4vector<int> d (c); // copy of c
1// CPP program to create an empty vector
2// and push values one by one.
3#include <bits/stdc++.h>
4using namespace std;
5
6int main()
7{
8 int n = 3;
9
10 // Create a vector of size n with
11 // all values as 10.
12 vector<int> vect(n, 10);
13
14 for (int x : vect)
15 cout << x << " ";
16
17 return 0;
18}
19