2d vector
C++
#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;}#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
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- how to extract substring from string in c++
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- how to append one vector to another c++
- Category
- C++
- Title
- c++ pi
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++
- Title
- to_string c++
- Category
- C++
- Title
- vertical traversal of binary tree
- Category
- C++
- Title
- advanced c++ topics
- Category
- C++
- Title
- sum of integer in array c++
- Category
- C++
- Title
- c++ string to integer without stoi
- Category
- C++
- Title
- mkdir c++
- Category
- C++
- Title
- visual studio 2019 read and write text file c++
- Category
- C++
- Title
- pointers in cpp
- Category
- C++
- Title
- c++ function to find length of array
- Category
- C++
- Title
- how to sort an array c++
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- how to iterate trough a vector in c++
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- c++ sort vector of objects by property
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- how to get a letter from the user c++ string
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- c++ compare char array
- Category
- C++
- Title
- bfs in C++
- Category
- C++
- Title
- C++ w3schools
- Category
- C++
- Title
- how to find the size of a character array in c++
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- for loop
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- c++ code for polynomial addition
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- how to measure program run time in c++
- Category
- C++
- Title
- convert char to string - c++
- Category
- C++
- Title
- how the theam are store in database
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- what is order in of preeendence in float, int, char, bool
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- calling by reference c++
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- pbds in c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- c++ initialize a vector
- Category
- C++
- Title
- c++ isalphanum
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- c++ random
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- passing array to function in c++
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- never gonna give you up
- Category
- C++
- Title
- templates of templates c++
- Category
- C++
- Title
- typeid to string c++
- Category
- C++
- Title
- C++ pointer arithmetic
- Category
- C++
- Title
- delay millis arduino
- Category
- C++
- Title
- c++ how to loop through a vector but not the last element
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++
- Title
- how to check datatype of a variable in c++
- Category
- C++
- Title
- sfml default program
- Category
- C++
- Title
- variabili in c++
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- initialize 2d array c++
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- vector stl c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- c++ wait for user input
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- c++ rainbow text
- Category
- C++
- Title
- file reading c++
- Category
- C++
- Title
- c++ read file line by line
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- c++ overloaded equality check operator
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- fill c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- unordered_set in c++ and ordered set diff
- Category
- C++
- Title
- what is time complexity of insertion sort
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- do while loop c++
- Category
- C++
- Title
- c++ compare char
- Category
- C++
- Title
- iostream library in cpp
- Category
- C++
- Title
- how to append an element to an array in cpp
- Category
- C++
- Title
- convert entire string to lowercase c++
- Category
- C++
- Title
- while loops
- Category
- C++
- Title
- Check if a Number is Odd or Even using Bitwise Operators
- Category
- C++
- Title
- C++ cin cout
- Category
- C++
- Title
- how to end a c++ program early
- Category
- C++
- Title
- pass ss tream as parameter c++
- Category
- C++
- Title
- how to use assrt c++
- Category
- C++