1#include <iostream>
2#include <vector>
3using namespace std;
4
5int main()
6{
7 vector<vector<int> > buff;
8
9 for(int i = 0; i < 10; i++)
10 {
11 vector<int> temp; // create an array, don't work directly on buff yet.
12 for(int j = 0; j < 10; j++)
13 temp.push_back(i);
14
15 buff.push_back(temp); // Store the array in the buffer
16 }
17
18 for(int i = 0; i < buff.size(); ++i)
19 {
20 for(int j = 0; j < buff[i].size(); ++j)
21 cout << buff[i][j];
22 cout << endl;
23 }
24
25 return 0;
26}
1vector<vector<int>> matrix(x, vector<int>(y));
2
3This creates x vectors of size y, filled with 0's.
4
1#include <iostream>
2#include <vector>
3using namespace std;
4
5int main()
6{
7 int n = 5;
8 int m = 7;
9 //Create a vector containing n vectors of size m and initalize them to 0.
10 vector<vector<int>> vec(n, vector<int>(m, 0));
11
12 for (int i = 0; i < vec.size(); i++) //print them out
13 {
14 for (int j = 0; j < vec[i].size(); j++)
15 {
16 cout << vec[i][j] << " ";
17 }
18 cout << endl;
19 }
20}
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}
1
2int main()
3{
4 int row = 5; // size of row
5 int colom[] = { 5, 3, 4, 2, 1 };
6
7 vector<vector<int> > vec(row); // Create a vector of vector with size equal to row.
8 for (int i = 0; i < row; i++) {
9 int col;
10 col = colom[i];
11 vec[i] = vector<int>(col); //Assigning the coloumn size of vector
12 for (int j = 0; j < col; j++)
13 vec[i][j] = j + 1;
14 }
15
16 for (int i = 0; i < row; i++) {
17 for (int j = 0; j < vec[i].size(); j++)
18 cout << vec[i][j] << " ";
19 cout << endl;
20 }
21}