#include<bits/stdc++.h>
using namespace std;
main()
{
vector<vector<int> > v;
for(int i = 0;i < 3;i++)
{
vector<int> temp;
for(int j = 0;j < 3;j++)
{
temp.push_back(j);
}
//cout<<typeid(temp).name()<<endl;
v[i].push_back(temp);
}
}
I am trying to assign to a two dimensional vector. I am getting the following error
No matching function for call to
std ::vector<int>::push_back(std::vector<int> &)
Problem: Your vector v
is empty yet and you can't access v[i]
without pushing any vector in v.
Solution: Replace the statement v[i].push_back(temp);
with v.push_back(temp);