在下面的代码中,我在最后一行收到了段错误:
int MAX_ITER = 4, n = 5;
vector< pair<int, vector<int> > > InputVector(MAX_ITER);
srand((unsigned)time(NULL));
for (int i = 0; i < MAX_ITER; i++)
InputVector[i].second.resize(n);
for (int i = 0; i < MAX_ITER; i++) {
InputVector[i].first = i+1;
for (int j = 0; j < InputVector[i].second.size(); i++)
InputVector[i].second[j] = rand()%2;
如何访问InputVector[i].second
的第j个元素?
答案 0 :(得分:3)
for (int j = 0; j < InputVector[i].second.size(); i++)
^^ should be j++