initialize 2D vector code example

Example 1: initialize 2d vector of ints c++

auto M = 4;	// num of rows
auto N = 3; // num of cols in each row
auto default_value = 1; // default value of all int elements
std::vector> matrix(M, std::vector(N, default_value));

Example 2: initializing 2d vector

vector > vec( n , vector (m, 0));

Example 3: initialising 2d vector

// Initializing 2D vector "vect" with 
// values 
vector > vect{ { 1, 2, 3 }, 
                           { 4, 5, 6 }, 
                           { 7, 8, 9 } };

Example 4: how to take input in 2d vector in c++

std::vector> d;
//std::vector d;
cout<<"Enter the N number of ship and port:"<>in;
cout<<"\Enter preference etc..:\n";
for(i=0; i>temp;
    d.push_back(temp);// I don't know how to push_back here!!
    }
}

Example 5: initialize 2D vector

vector >    v2(8, vector(5));

Tags:

Misc Example