When i compile this prog, i get errors sayin
1.'d' undeclared"
2.Each undeclared identifier is reported only once for each function it appears in. what is the problem here with declaration of an array of vectors??
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int m,a,b,i;
cin>>m;
for(i=0;i<m;i++)
{
vector<int> d[i];
}
for(i=0;i<m;i++)
{
cin>>a>>b;
d[a].push_back(b);
}
return 0;
}
@zhuge yep i've got it.. but for declaring an array of vectors,, i need a loop.. so how do i define it in a better scope,, i.e how do i define it such tat it can be accessed throughout the main() function??
There are two problems with the original code. d only exists within the scope of the first for statement, and one may not define an array with a variable that is not also a compile-time constant: i, although some compilers have an extension enabled by default that allows it.
Since you're already using a vector, why not just use a vector of vectors?