size of a matrix using vector c++
C++
#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;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int rows = 2;
int cols = 2;
int val = 1;
vector< vector<int> > v(rows, vector<int> (cols, val)); /*creates 2d vector “v[rows][cols]” and initializes all elements to “val == 1” (default value is 0)*/
v[0][0] = 5;
v[1][1] = 4;
cout << v[0][0] << endl; //Output: 5cout << v[1][0] << endl; //Output: 1return 0;}// finding size of a square matrix
myVector[0].size();
Also in C++:
- Title
- array<string, 7> c++
- Category
- C++
- Title
- mkdir boost filesystem
- Category
- C++
- Title
- matrix class in c++
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- *max_element in c++
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- first fit algorithm
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- c++ get ascii value of char
- Category
- C++
- Title
- root to leaf path print
- Category
- C++
- Title
- filling 2d array with 0 c++
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- c++ while true
- Category
- C++
- Title
- c++ remove text file
- Category
- C++
- Title
- How to traverse in a tree iterative C++
- Category
- C++
- Title
- array search c++
- Category
- C++
- Title
- index string c++
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- self in c++
- Category
- C++
- Title
- pyqt connect
- Category
- C++
- Title
- c++ lettura file
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- bitset c++
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- how to convert a string to a double c++
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- appending a double to a string c++
- Category
- C++
- Title
- pointer related problems dangling/wild pointers c++
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- error: invalid use of template-name without an argument list
- Category
- C++
- Title
- cpp pi from acos
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- substr in c++
- Category
- C++
- Title
- extends c++
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- c++ function return pointer to itself
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- insert function in c++ vector
- Category
- C++
- Title
- caesar cipher program in c++
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- nan c++ example
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- pointers in cpp
- Category
- C++
- Title
- c++ isalphanum
- Category
- C++
- Title
- is not a nonstatic data member or base class of class
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- pop from between string c++
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- inserting an element in an set c++
- Category
- C++
- Title
- double max value c++
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- reverse a linked list using recursion
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- int max in c++
- Category
- C++
- Title
- how to use max_element in c++ with vector
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- c++ convert int to double
- Category
- C++
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- c++ overload operator
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- ternary operator c++
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- iterate through unordered_map c++ in reverse order
- Category
- C++
- Title
- in c, is class uppercase or lowercase
- Category
- C++
- Title
- array 2d to 1d
- Category
- C++
- Title
- *min_element in c++
- Category
- C++
- Title
- variable sized arrays hackerrank solution in c++
- Category
- C++
- Title
- merge sort in c++
- Category
- C++
- Title
- visual studio 2019 read and write text file c++
- Category
- C++
- Title
- do while loop c++
- Category
- C++
- Title
- exponenciacion binaria
- Category
- C++
- Title
- including cpp header file in c++
- Category
- C++
- Title
- for loop in c++ hackerrank solution
- Category
- C++
- Title
- hohw toparse a string in c++
- Category
- C++
- Title
- Create a program that finds the minimum value in these numbers
- Category
- C++
- Title
- c++ vector add element
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- vectors in c++ geeksforgeeks
- Category
- C++
- Title
- initialize 2d array c++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- gfg right view of tree
- Category
- C++
- Title
- -> cpp
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- elseif c++
- Category
- C++
- Title
- stoi c++
- Category
- C++
- Title
- heap sort
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- c++ passing two dimensional array to function
- Category
- C++
- Title
- ceil c++;
- Category
- C++
- Title
- digitalwrite C++
- Category
- C++
- Title
- c++ replace substrings
- Category
- C++
- Title
- c++ file to string
- Category
- C++
- Title
- ue4 c++ struct
- Category
- C++