i am writing a program that will intake value of a 2 dimensional vector and provide them a output.But,i am getting a runtime error.
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
vector<vector<int> > vec;
vec[0].push_back(1);
vec[0].push_back(2);
vec[0].push_back(13);
for(int i=0;i<3;i++)
{
cout<<vec[0][i]<<" ";
}
return 0;
}
Your vector of vectors is empty. You can't do
vec[0].push_back(1);becausevec[0]doesn't exist. You can solve that problem by making your vector of vectors with a size of at least1by specifying that in the constructor. Change thisTo this:
Alternatively you could
push_backa vector into your vector of vectors: