Answers for "size of vector in vector in c++"

C++
7

how to make a 2d vector in c++

// Create a vector containing n 
//vectors of size m, all u=initialized with 0
vector<vector<int> > vec( n , vector<int> (m, 0));
Posted by: Guest on June-19-2020
13

c++ vector size

#include <vector>

int main() {
  std::vector<int> myVector = { 666, 1337, 420 };
  
  size_t size = myVector.size(); // 3
  
  myVector.push_back(399); // Add 399 to the end of the vector
  
  size = myVector.size(); // 4
}
Posted by: Guest on May-16-2020
1

c++ 2D vectors

int main() 
{ 
    int row = 5; // size of row 
    int colom[] = { 5, 3, 4, 2, 1 }; 
  
    vector<vector<int> > vec(row);  // Create a vector of vector with size equal to row. 
  	for (int i = 0; i < row; i++) { 
  		int col;  
        col = colom[i]; 
  		vec[i] = vector<int>(col); //Assigning the coloumn size of vector
        for (int j = 0; j < col; j++) 
            vec[i][j] = j + 1; 
    } 
  
    for (int i = 0; i < row; i++) { 
        for (int j = 0; j < vec[i].size(); j++) 
            cout << vec[i][j] << " "; 
        cout << endl; 
    } 
}
Posted by: Guest on July-27-2020
-1

declare vector of size n in c++

#include <vector>

auto n = 20
// create a vector with n=20 integer elements
std::vector<int> arr(n);
Posted by: Guest on September-13-2020

Browse Popular Code Answers by Language