1
2vector<int> vec;
3//Creates an empty (size 0) vector
4
5
6vector<int> vec(4);
7//Creates a vector with 4 elements.
8
9/*Each element is initialised to zero.
10If this were a vector of strings, each
11string would be empty. */
12
13vector<int> vec(4, 42);
14
15/*Creates a vector with 4 elements.
16Each element is initialised to 42. */
17
18
19vector<int> vec(4, 42);
20vector<int> vec2(vec);
21
22/*The second line creates a new vector, copying each element from the
23vec into vec2. */
1#include <iostream>
2#include <vector>
3using namespace std;
4
5int main() {
6 //vector element size
7 const int size = 4;
8 //vector with int data type
9 //all elements are equal to 4
10 vector<int> myVect (size, 4);
11
12 for (int i=0; i<size; i++) {
13 cout << "Vector index(" << i <<") is: "<< myVect[i] << endl;
14 }
15 return 0;
16}