Pergunta

In the following code, I receive segfault at the last line:

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;

How to access jth element of InputVector[i].second?

Foi útil?

Solução

for (int j = 0; j < InputVector[i].second.size(); i++) 
                                                  ^^ should be j++
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top