I keep getting an out of range error when I try to populate a 2d vector in c++. Where am I going wrong? Posted below is a shortened version of my problem that I believe generates the same problem.
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <iostream>
typedef std::vector<double> NA;
typedef std::vector<NA> NB;
NA NI;
NB NO;
long i=0,j=0;
int N = 10;
double R;
int main(){
for(i=0;i!=N;i++){
NO.push_back(NI);
for(j=i+1;j<N;j++){
R = rand();
NO.at(i).push_back(j);
NO.at(i).at(j) = R;
}
}
}
NO.at(i).at(j) = R;
shouldn't compile? In fact it doesn't: ideone.com/ukPags