how to get size of 2d vector in c++
C++
myVector[
Vector[0, 4, 2, 5],
Vector[1, 4, 2]
];
/*When you call for myVector[1].size() it would return 3 and [0] would return 4.
For the amount of rows (int vectors) in the 2d vector, you can just use myVector.size()
You can run this to see it in actions*/// finding size of a square matrix
myVector[0].size();#include<bits/stdc++.h>
using namespace std;
int main(){
int n = 3;
int m = 4;
// Create a vector containing n
//vectors of size m.
vector<vector<int> > vec( n , vector<int> (m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++){
cout<< vec[i][j]<< " ";
}
cout<< "\n";
}
return 0;
}
// Initializing 2D vector "vect" with
// values
vector<vector<int> > vect{ { 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 } }; // Create a vector containing n
//vectors of size m, all u=initialized with 0
vector<vector<int> > vec( n , vector<int> (m, 0));
Also in C++:
- Title
- c++ evaluate expression
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- namespace file linking c++
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- create new file c++
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- kruskal's algorithm c++ hackerearth
- Category
- C++
- Title
- how do for loops on c++
- Category
- C++
- Title
- c++ compiler for sublime text
- Category
- C++
- Title
- insert elements in array in c++11
- Category
- C++
- Title
- conditional operator in cpp
- Category
- C++
- Title
- preorder traversal
- Category
- C++
- Title
- c++ class member initialization
- Category
- C++
- Title
- how to output text in c++
- Category
- C++
- Title
- what is time complexity of insertion sort
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- loop through array c++
- Category
- C++
- Title
- c++ convert const char* to LPCWSTR
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- leveling system c++
- Category
- C++
- Title
- how to compare two strings lexicographically in c++
- Category
- C++
- Title
- c++ convert int to cstring
- Category
- C++
- Title
- reverse in vector c++
- Category
- C++
- Title
- swapo algorit
- Category
- C++
- Title
- c++ char define
- Category
- C++
- Title
- c++ create object
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- map.erase in c++
- Category
- C++
- Title
- power in c++
- Category
- C++
- Title
- initialising 2d vector
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- c++ random numbers
- Category
- C++
- Title
- calling a method on an object c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- how to find the index of an element in a vector c++
- Category
- C++
- Title
- shuffle vector c++
- Category
- C++
- Title
- mark occurances of elements in array cpp
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- ue4 c++ struct
- Category
- C++
- Title
- variabvles in c++
- Category
- C++
- Title
- c++ show time elapsed
- Category
- C++
- Title
- binary representation differ in bits
- Category
- C++
- Title
- compare values within within a vector c++
- Category
- C++
- Title
- range based for loop c++
- Category
- C++
- Title
- c++ convert int to double
- Category
- C++
- Title
- two sum problem in c++
- Category
- C++
- Title
- opperanf >> c++
- Category
- C++
- Title
- inconsequential meaning
- Category
- C++
- Title
- c++ isalphanum
- Category
- C++
- Title
- howt o initialize 3d vector in c++
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- how to print eachh chars in string data type in c++
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- how to type cast quotient of two integers to double with c++
- Category
- C++
- Title
- accumulate in cpp
- Category
- C++
- Title
- rand c++
- Category
- C++
- Title
- unordered_set in c++ and ordered set diff
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- c++ wait for user input
- Category
- C++
- Title
- set precision in c++
- Category
- C++
- Title
- declare vectors c++
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- merge sort in c++
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- vector initialization c++
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- c++ vector add element
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- double max value c++
- Category
- C++
- Title
- C++ w3schools
- Category
- C++
- Title
- assegnare valori in c++
- Category
- C++
- Title
- c++ loop trhought object
- Category
- C++
- Title
- how to iterate trough a vector in c++
- Category
- C++
- Title
- vector concat c++
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- c++ push multiple elements to vector
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- c++ code 2d block
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- c++ template function
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- c++ random
- Category
- C++
- Title
- convert int to string c++
- Category
- C++
- Title
- runtime error in c++
- Category
- C++
- Title
- do while loop c++
- Category
- C++
- Title
- deque c++
- Category
- C++