Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

2D vector in C++ with user defined size

#include <iostream>
#include <vector> //header file for 2D vector in C++
using namespace std;
int main() {
   vector<vector<int> > v{ { 4,5, 3, 10 }, // initializing 2D vector with values.
   { 2, 7, 11 },
   { 3, 2, 1, 12 } };
   cout<<"the 2D vector is:"<<endl;
   for (int i = 0; i < v.size(); i++) { // printing the 2D vector.
      for (int j = 0; j < v[i].size(); j++)
      cout << v[i][j] << " ";
      cout << endl;
   }
   return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.