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// First include the vector library:
2#include <vector>
3
4// The syntax to create a vector looks like this:
5std::vector<type> name;
6
7// We can create & initialize "lol" vector with specific values:
8std::vector<double> lol = {66.666, -420.69};
9
10// it would look like this: 66.666 | -420.69
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
1#include <bits/stdc++.h>
2#include <vector>
3using namespace std;
4
5int main()
6{
7// This vector initializes with the values: 10, 20, and 30
8 vector<int> vect{ 10, 20, 30 };
9
10 return 0;
11}