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++ get string between two characters 
Cpp :: c++ splitstring example 
Cpp :: how to make an overloaded constructor in c++ 
Cpp :: C++ String Length Example 
Cpp :: how to delete a file in cpp 
Cpp :: c++ string to char array 
Cpp :: C++ Structures (struct) 
Cpp :: c++ how to add something at the start of a vector 
Cpp :: c++ hello world 
Cpp :: c++ array size 
Cpp :: iterate over vector in c++ 
Cpp :: c++ modulo positive 
Cpp :: sizeof operator in c++ 
Cpp :: c++ program to print natural numbers from 1 to 10 in reverse order using while loop 
Cpp :: remove space in string c++ 
Cpp :: c++ progress bar 
Cpp :: str remove char c++ 
Cpp :: Find minimum maximum element CPP 
Cpp :: how to find something in a string in c++ 
Cpp :: stack implementation through linked list 
Cpp :: c++ base constructor 
Cpp :: check if element in dict c++ 
Cpp :: vector library c++ 
Cpp :: how to generate number in c++ 
Cpp :: factorial of large number 
Cpp :: c++ how to return an empty vector 
Cpp :: cpp linked list 
Cpp :: c++ variable types 
Cpp :: how to empty a std vector 
Cpp :: sweetalert2 email and password 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =