title: Are vector elements guaranteed to be in order?
body: <p>I understand that having pointers to elements of a vector is a bad idea, because upon expanding, the memory addresses involved will change, therefore invalidating the pointer(s). However, what if I were to simply use an integer that holds the index number of the element I want to access? Would that be invalidated as the vector grows in size? What I am thinking of looks something like this:</p>
  
  <pre><code>    #include &lt;vector&gt;
  
      class someClass{
      string name
      public: string getName(){return name;}
      };
  
      vector&lt;someClass&gt; vObj;
      int currIdx;
      string search;
      cout&lt;&lt;"Enter name: ";
      cin&gt;&gt;search;
  
      for(int i=0; i&lt;vObj.size(); i++){
        if(vObj[i].getName()==search)
           currIdx = i;}
  </code></pre>