1// Create a vector containing n
2//vectors of size m, all u=initialized with 0
3vector<vector<int> > vec( n , vector<int> (m, 0));
1myVector[
2 Vector[0, 4, 2, 5],
3 Vector[1, 4, 2]
4];
5
6/*When you call for myVector[1].size() it would return 3 and [0] would return 4.
7
8For the amount of rows (int vectors) in the 2d vector, you can just use myVector.size()
9
10You can run this to see it in actions*/
1std::vector<vector<int>> d;
2//std::vector<int> d;
3cout<<"Enter the N number of ship and port:"<<endl;
4cin>>in;
5cout<<"\Enter preference etc..:\n";
6for(i=0; i<in; i++){
7cout<<"ship"<<i+1<<":"<<' ';
8 for(j=0; j<in; j++){
9 cin>>temp;
10 d[i].push_back(temp);
11 }
12}
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}
1std::vector<vector<int>> d;
2//std::vector<int> d;
3cout<<"Enter the N number of ship and port:"<<endl;
4cin>>in;
5cout<<"\Enter preference etc..:\n";
6for(i=0; i<in; i++){
7cout<<"ship"<<i+1<<":"<<' ';
8 for(j=0; j<in; j++){
9 cin>>temp;
10 d.push_back(temp);// I don't know how to push_back here!!
11 }
12}