initialize 2D vector

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<std::vector<int>> matrix(M, std::vector<int>(N, default_value));

3.5
2
Graham Yates 155 points

                                    std::vector&lt;vector&lt;int&gt;&gt; d;
//std::vector&lt;int&gt; d;
cout&lt;&lt;&quot;Enter the N number of ship and port:&quot;&lt;&lt;endl;
cin&gt;&gt;in;
cout&lt;&lt;&quot;\Enter preference etc..:\n&quot;;
for(i=0; i&lt;in; i++){ 
cout&lt;&lt;&quot;ship&quot;&lt;&lt;i+1&lt;&lt;&quot;:&quot;&lt;&lt;' ';
    for(j=0; j&lt;in; j++){
    cin&gt;&gt;temp;
    d.push_back(temp);// I don't know how to push_back here!!
    }
}

3.5 (2 Votes)
0
4.43
7

                                    vector&lt;vector&lt;int&gt; &gt;    v2(8, vector&lt;int&gt;(5));

4.43 (7 Votes)
0
4.67
3

                                    // Initializing 2D vector &quot;vect&quot; with 
// values 
vector&lt;vector&lt;int&gt; &gt; vect{ { 1, 2, 3 }, 
                           { 4, 5, 6 }, 
                           { 7, 8, 9 } }; 

4.67 (3 Votes)
0
4.33
3
Hunter C 95 points

                                    vector&lt;vector&lt;int&gt; &gt; vec( n , vector&lt;int&gt; (m, 0));

4.33 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
initialising 2d vector with values how to initialize a 2D vector with all same value in c++ initializing 2d vector initialize a 2d vector c++ with another vector 2d vector initialization initialize 2d vector c++ with all values initialising a 2d vector c++ how to initialize 2d vector as 0 in cpp initialize 2d vector c++ with values initialize 2d vector with NULL c++ initialize a 2d vector cpp how initialize 2D vector c++ input in 2d vector 2d array input in c++ initializeing a 2d vector 2d vector initialising with 0 initialize 2d vector c++ 0 initialize a 2d matrix with 0 in vector how to iniitialize 2d vector initialise a 2d vector with size c++ input in a 2d array 2d vector intitalizetino initialize 2d vector with some values user input 2d array c++ how to initialize 2d vector in c++ glo c++ init 2d vector intialize 2d vector c++ initialise a 2d vector with a empty vector how to take input in 2d array c++ initialize 2d vector in c++ 2d vector initialize 2d vector initialize with 0 cpp how take input/output in 2d vector initialize 2d vector c++ with default value how to initialize a 2d vector in cpp initialize empty 2d vector c++ ways to input 2d array in c++ 2d vector c++ initialization 2d array input function c++ initializing one element of 2d vector in c++ with 0 using stl how to take user input in 2d vector in c++ how to take input 2d array in c++ 2d array how to initalize vector how to initialize a 2d vector in c++ how to initalize a 2d vector init 2d vector of vectors c++ how to take input of a 2d vector in c++ initialize a 2d vector in c++ inntialize 2d vector c++ initialyze 2d vector c++ how to initialize a 2d vector in c++ with default values take 2d array input from user in c++ 2d matrix input in c++ cpp 2d vector initialization how to take a 2d vector as input in c++ initialize 2d vector of sets cpp 2d vector input how to input a 2d array in c++ 2d vector c++ initialize 1 how to initialize 2d vector in c++ with 0 initialise a 2d vector c++ vector 2d array input taking input in 2d array in c++ initialaize 2D vector in c++ vector 2d dimension initialize input 2d array in c++ initialize 2d matrix c++ vector initialized 2d vector with 0 vector initialization c++ 2d initialise 2D vector initialize 2d vector with values take 2d array input in c++ how to input a 2d character vector in c++ 2d vector initialization in c++ initialising 2d vectors in c++ initialize 2d int array c++ intialize 2d vectorcc++ how ot initialize 2d vector how to initialize a 2d vector with values how to initialize all the elements of a 2d vector how to initialize 2d vector with 0 in c++ 2d vector c++ user input initialize 2d vector c++ after declaration initialising a 2d vector how to take input in 2d vector create a 2d vector and initialize all c++ how to initialze 2d vector with 0 c++ initializing 2D vector c++ initialize a 2d vector in cpp initialising 2d vector in cpp 2d vector in c++ manualu input how to take input of 2d array in c++ how to intialize 2d vector initialize vector 2d c++ initialization of 2d vector in c++ initialized 2d vector c++ intialize an vector 2d how to take input in 2d array in c++ 2d array input c++ take input in 2d array in c++ initialize a 2d vector 2d vector c++ initialize with 0 initiate 2d vector instantiate 2d vector c++ initialize 2d vector c++ constructor how to initialize a 2d vector with -1 globally input 2d array c++ how to input 2d array in c++ how to initialize a 2d vector with -1 c++ set values of multidimensional vector at init intilisation of 2d vector c++ how to define multidimensionalvector size at initialization sets the values in the matrix to the same values as in a same sized 2D vector that is passed into the method user input 2d vector c++ iniitialise 2d vector how to input vector in c++ how to input in 2d array c++ initialising 2d vector c++ predefine the size of 2d vector in cpp std vector define size multidimensional create matrix using vector c++ matrix in vector c++ 2d vector fill in c++ initializing a 2d vector using vector as 2d array intitalize 2D vector C++ initialising a vector initialising a 2d vector of some variable vector 2d initialize how to input a vector in c++ intializing 2d vectors c++ vector matrix initialization initialized vector of vector c++ matrix c++ vector 2d array vector d++ 2d vector access 2d vectors 2 dimensional vector c++ example declare 2d vector init 2dimensional vector c++ how to find an element in 2d vector c++ passing 2d vector c++ how to add size to two dimentional vector dynamicaly c++ dynamic n dimensional vector c++ multidimensional vector specify ize c++ multidimensional vector specify by default values in 2d vector 2d vector at c++ 2d matrix vector c++ how to make two dimensional vector in c++ c++ 2d vector define size initialize size of 2d vector c++ initialise 2d vector of 0s 2d vector in c++ with user defined size traverse a 2d vector c++ initialsize a 2d vector of strins with a char in cpp initialize vector to 0 c++ how to initialise 2d array initialize a multi dim vector c++ initialzing a 2-d vector how to initialize a vector of pairs in c++ how to make a fixed size 2d vector c++ vector of vector initialization c++ how to take infinite input in vector c++ create 2d vector with size c++ 2d vector of size n with all value -1 in c++ how to initialize a 2d array in c++ intitilaising a 2d vector in cx++ how to call2d vector Declaring @d vector how to initialise a 2d vector without fixed size in c++ how to display the elements of 2d vector in c++ using .at() 2d vector in c++ initialization 2d array initialisation initialize a 2d vector with another 2d vector c++ unity 2d vector2.normalize c++ vector 2d array initialize vector 2d matrix no of columns of 2d vector how to make a define 2d vector initilasise a multi dim vector c++ using vector in c++ to construct 2d array using vector in c++ to store 2d value how to initialize a multidimentional vector to zero in c++ how to work for 2d vectors 2d vector c++ input how to define an empty 2d vector in c++ c++ initialize 2d vector to 0 how to initialize 2d vector instantiate a vector matrix in c++ how to add to 2d vector c++ user defiined size 2d vector how to declare a 2d vector how to print 2-d vector how to initialize a 2d vector to all zeroes dealing with 2D vectors in c++ how to initialize a 2d vector dynamically 2d vector init c++ c++ resize 1d vector into 2d vector 2d vector methods initialize two dimensional vector c++ size how to initialize 2d vector in cppp initializing a 2d vector c++ size of vector of vectors c++ initialize 2d vector of ints how to declare an nxn vector i c++ how to declarea 2d vector in c++ initialize vector of vector how to assign a 2d array to vector c__ how can I declare mutliple 2d vectors in c++ c++ fill 2d vector how to initialize 2d vector C++ 2 dimensional vector array c++ multidimentional vector c++ initialization how to initalize a 2d vector to false multi dimensional vector c++ stl 2 d vector in cpp with initial value accept input for 2d vector in c++ 2d vector sizew declaration 2d vector in ++ how to initalize c++ 2d vector with values 2 dimensional vector c++ initialize c++14 initialize 2d vector vector vector int initialize c++ how to intialize a 2d vector with 2d array in c++ 2d array stl set 2d vector size c++ make 2d vector in c++ c++ 2d vector generate c++ initial 2d vector how to create a 2d string vector cpp cpp vector matrix initialization c++ construct 2d vector c++ vector 2d initialization creating a 2d vector in c++ size of matrix vector in c++ initialize 2d vector c++ to zero initialising a vector of vectors c++ how to take input in two dimensional vector in c++ initializing vector of vector c++ initializing vector of vectors c++ vector of vector of int initialization c++ two dimensional vector initialization vector&lt;vector&lt;int&gt;&gt;assign size 2d vector indexing c++ two dimensional vector c++ initialization input values in vector matrix c++ 2d vector .size() c++ vector pf int vector of variable length in c++ vector 2d c++ c++ initialiser vector &agrave; 2 dimensions n by n 2d vector 2d vecgor c++ how to build 2d vecto 2d vector c++ tutorial 2d vectors initialize with zeros take input in 2d vector 2d vector intialize with 0 2d vactor c++ how to initialize 2d vector in c++ 2d vector of indefinite size c++ stl 2d array 2d vector initialization with size and init value c++ how to initialize 2dvector in c++ of some size how to set size of 2 dimensional vector in c++ declaring matrix using vector c++ c++ 2d vector indexing initialise 2d vector c++ traverse a 2d vector in c++ 2D vector cplusplus how to allocate memory for a 2d vector array c++ multidimensional array using vector in c++ how to initialise 2d vector in c++ declaring the size of 2-d vector c++ two dimensional vector example initialize multidimensional vector how to initialise a 2d vector in cpp cpp 2d vector how to find value in every row in 2d vector 2d vector array cpp how to initialise vector with size c++ declare 2d vector c++ in one line enter a vector&lt;vector&lt;int&gt;&gt; how to intialise a 2d vector with 4 rows 2 collumns how to intialise a 2d vector with 4 rows how to intialise a 2d vector c++ initialize size of 2 dimensional vector initialize vector with size c++ 2d array using std vector c++ two dimensional vector c++ of fixed size initialize 2d vector c++ initialize 2d vector with values how to initailize vector with lenght c++ 2d vector to 2x2 vector return a row of 2d vector double vector in c++ 2d matrix using vector c++ user input of 2d vector c++ C++ vector two-dimensional array initialise a 2d vector c++ create and initialise 2d vector c++ cpp initialize 2d vector vector to vector 2d get 2d vector size c++create a 2D vector can we assign 2d vector to another c++ how to initialise 2d vector how to store 2d vector in C++ 2d array input in vector c++ how to make 2d vector with defined size initialize 2d vector c++ with 0 initialize vector matrix c++ 2d vector declaration initialize double vector c++ with new c++ two dimensional vector with fixed size c++ double vector initialization 2d vector of fixed size vector&lt;vector&lt;int&gt;*&gt; input how to insert in 2d vector declare vector of vector c&acute;&acute; intialize 2d vector declaring 2d vector how to create a 2 dimensional vector in c++ declaring 2d vector with size how to create 2d vector array double vector declaration of 2d vector in c++ null vector example in c++ for 2d vector how to iterate 2d vector in c++ C++2D vector at he recommended approach is to use fill constructor to initialize a two-dimensional vector with a given default value : std::vector&lt;std::vector&lt;int&gt;&gt; fog(M, std::vector&lt;int&gt;(N, default_value)); where, M and N are dimensions for your 2D vector. set 2D vector to 0 in C++ accessing elements of 2d vector c++ how to define a matrix in C++ VECTOR c++ set size of 2d vector two dimensional vector use a vecto as a 2d array 2d vector c++ row and column size 2D vector int or long 2d vector c++ gfg 2d vectors initialize 2d vector of zeros vector 2D how to take 2d vector input in c++ initializing a vector of vectors c++ how to give size to 2d array in c++ using int size of a 2d vector initializing 2d vector c++ with values make 2d vector all zeros c++ declare a 2d vector c++ c++ 2 dimensional vector initialization how to initialise a 2d vector in c++ c++ 2 dimensional vector fix size vector matrix size c++ vector of a 2d array initialize the size of two dimensional vectro c++ cin 2d vector in c++ c++ vector size initialization initialize 2d vector of ints c++ 2D matrix c++ using vector with user input 2d array c++ using vector 2d vector c++ of string 2 dimensinonal vector c++ vector of vector c++ initialize make 2d vector c++ initialize two dimensional vector c++ taking input for 2d vector array how to take input from user in 2d vector in c++ take input in 2d vector c++ taking input in dynamic 2d array in c++ vector how to initialize 2Dvector in c++ initialize 2d vector c++ with size declare and initialize 2d vector c++ how to declare a two dimentional vector in c++ initialize vector with 2d array c++ 2 d vectors in c++ enter vlues by user in 2 d vector in c++ add values by user in 2 d vector c++ c++ vector two dimensional declare a 2d vector in c++ double dim vector variable length c++ 2d vector c++ undefined size how to give input in 2d vector in c++ initialize 2d vector to 0 c++ 2d vectors c++ initializing 2d vector in c++ creating a 2d vector in c++ and initializing to 0 initialize 2d vector after declaration with 0 c++ initialize 2d vector with 0 c++ initialize 2d\ vector c++ vector&lt;vector&gt;&gt; cpp initialization how to create a matrix using vector in c++ how to define 2d vector in c++ two dimensional vectors c++ 2d vector input c++ 2d vector in c++ declare 2d vector c++ matrix as vector c++ vector 2d array p5ja 2d vector initialize c++ ip 2d vector c++ initialize ndimensional vector c++ c++ 2d vector input 2d vector c++ how to access elements in a 2d vector c++ using 2d vector in c++ initializing 2d vector in cpp declare 2d vector c++ with size print 2d vector c++ initialise 2d vector with 0 c++ vector 2d in c++ input declaring 2d vector with fixed space in c++ defining a 2d vector with specified row and column size in c++ quick print 2d vector c++ high dimensional vectors c++ how to calculate size of vector of vectors in c++ how to input a 2d vector in c++ how to declare a two dimensional vector in c++ vector of vector size c++ initialize vector of vector c++ with sizde initialize vector of vector c++ c++ 2D vectors ve tor 2d arrays how to create a two dimensional vector in c++ intialising 2d vector c++ create a 2d vector c++ create 2d array using vector matrix using vector c++ 2d vector in cpp constructor variable size 2d array c++ using vector how to declare a 2d vector c++ how to 2d vector c++ declare size of 2d vector c++ multidimensional vector c++ initialization how to declare 2d vector in c++ how to declare size of 2d vector in c++ how to take input in 2d vector in c++ initialize 2d vector java c++ 2d vector access element 2d array of vectors c++ initialize vector of vectors c++ init 2d vector c++ define size of 2d vector c++ 2-d vector functions c++ initialize 2d vector with all zeros fill 2d vector c++ 2d string vector c++ two dimensional vector c++ c++ initialize 2d vector multidimensional vector c++11 initialize a vector of vectors c++ assigning 2d vector c++ declare 2 dimensional vector c++ two d vector c++ initialize a 2d vector c++ 2 D vector in c++ initialize vector of vector c++ with size initialize empy multi dimensional vectors of objects c++ initialize multi dimensional vectors of objects c++ how to create two dimensional vector in c++ how to initialize a 2d vector initializing two dimensional vector c++ how to declare nested vector in c++ how to initialize all elements in an 2d vector to zero in c++ vector of defined size c++ how to make a 2d vector in c++ how to initialize two dimensional vector in c++ c++ 2d vector of given size declare two dimensional vector c++ declaring a 2d vector in c++ intialise 2d vector using new to declare 2d array in c+= stl 2d vector in cpp c++ access 2d vector element assign 2d vector to another vector c++ size of 2d vector c++ how to initialize a 2d vector in c++ with 0 how to declare 2d vector in c++ create two dimensional vector c++ 2-d dyanmic vector c++ filliing 2d vector c++ 2d vector initialization nested vector c++ assign 2d vector in c++ 2-d vector in c++ 2d vectors in c++ empty 2d vector of size 4 * 2 multidimensional vectors in c++ how to initialize vector of vector in c++ how to fill 2d vector cpp 2d vectort initialising 2d vector push_back c++ vector of vecotr with size c++ how to intitalize 2d vector elements as zero in c++ 2d vector with predefined dimensions in c++ 2d vector range 2d vecotr handling how to make 2d vector std::vector 2 dimensinal arrays 2d vector how to insert a vector into a 2dvector c++ define 2d vector 2d vector initialization c++ how to get size of 2d vector in c++ how to declare a 2d vector in c++ multidimensional vector c++ making a 2d vector c++ c++ vector 2d array initialize 2d vector c++ 2d vector c++ 2d vector c++ initialize initialising a 2d vector cpp 2d array vector c++ declaring 2d vector in c++ 2d vector in c++ declare 2d vector with size c++ initializing a 2d vector in c++ initialise 2d vector in c++ initialising 2d vector
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source