Search
 
SCRIPT & CODE EXAMPLE
 

CPP

2d vector c++ size

vector<vector<int>> a;
int r=a.size() //gives no of rows
  int c=a[0].size() //gives no of columns
Comment

how to get size of 2d vector in 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*/
Comment

2d vector size c++

#include <iostream>
#include <vector>

int main(){
    std::vector<std::vector<int>>MyVector;
  std::cout << "Rows in the 2d vector: " << MyVector.size() <<
    std::endl << "Collumns in the 1st row: " << MyVector[0].size() <<
    std::endl;
  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ string to int conversion 
Cpp :: split string on character vector C++ 
Cpp :: latex table landscape 
Cpp :: loop through a vector in c++ 
Cpp :: adding element in vector c++ 
Cpp :: insert vector to end of vector c++ 
Cpp :: int_max cpp 
Cpp :: read text from file c++ 
Cpp :: binary file in c++ 
Cpp :: c++ typeid 
Cpp :: how to get an element in a list c++ 
Cpp :: sieve cpp 
Cpp :: how to take space separated input in c++ 
Cpp :: c++ foreach 
Cpp :: aray of functions in c++ 
Cpp :: vector size for loop 
Cpp :: c++ iterate over vector of pointers 
Cpp :: how to get the type of a variable in c++ 
Cpp :: c++ call by reference 
Cpp :: how to initialize array with new in c++ 
Cpp :: how to code string to int converter c++ 
Cpp :: iterate over vector in c++ 
Cpp :: c++ logger class example 
Cpp :: inline function in c++ 
Cpp :: methods available for a stl vector 
Cpp :: implementing split function in c++ 
Cpp :: c++ uint32_t 
Cpp :: how many months have 31 days 
Cpp :: life the universe and everything solution c++ 
Cpp :: vector library c++ 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =