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 <vector>
2
3using namespace std;
4
5int main(){
6 vector<int> v;
7 //vector<type> name
8
9 return 0;
10}
1typedef std::vector<std::vector<double> > Matrix;
2
3Matrix matrix = { {0.1,1.1,.2},
4 {.4,.5,.6},
5 {.8,.9,.10}
6 };
7// Just initilization:
8int rows = 3;
9int cols = 3;
10Matrix m3(rows, std::vector<double>(cols) );