title: Segmentation fault in c++ program using vector
body: <p>I received a segfault when running my code. The code contains a for loop and segmentation fault doesn't appear when I run the program for smaller iterations. It appears when I run the code for the larger loop.
  I used a debugger to check where doe the problem occurs:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x00000000004062d0 in std::vector&lt;int, std::allocator&lt;int&gt; &gt;::push_back (
      this=0x64dc08, __x=@0x7fffffffd180: 32)
      at /usr/include/c++/5/bits/stl_vector.h:915
  915     if (this-&gt;_M_impl._M_finish != this-&gt;_M_impl._M_end_of_storage)
  </code></pre>
  
  <p>What does it mean? Does anyone know? The code error is related to this part of the code: </p>
  
  <pre><code>  int box_new = getBoxID(x[i],y[i],R0,nbox);
              if(bx[i] != box_new)
                  {
                  vector&lt;int&gt;::iterator position = std::find(box_particles[bx[i]].begin(), box_particles[bx[i]].end(), i);
                  if (position != box_particles[bx[i]].end()) // .end() means the element was not found
                      box_particles[bx[i]].erase(position);
                  bx[i] = box_new;
                  box_particles[box_new].push_back(i);
                  }
  </code></pre>