title: How can I increment a vector iterator?
body: <p>I am learning how to work with vectors in my C++ college class. I have ran into an issue that has been keeping me from using iterators with vectors. This is my source code:</p>
  
  <pre><code>template &lt;class T&gt;
  void HuffMan&lt;T&gt;::search_freq(T temp) {
     //checks for frequency
     if(objects.empty()){
     objects.push_back(temp);
     return;
  }
  
  vector&lt;T&gt;::iterator it = objects.begin();
  
  while(it != objects.end()) {
     if(*it == temp)
       cout&lt;&lt;"added aready\n";
    else
       objects.push_back(temp);
  
    //this is where the error occurs
    //I cannot call 'it++' for some reason
    it++;
   }
  }
  </code></pre>
  
  <p>This code always returns a run time error that says 'vector iterator not incrementable'. I have tried to change the while loop into a for loop but I don't think that has to do with anything with the error. </p>
  
  <p>Info: My vector object is declared as follows:</p>
  
  <pre><code>vector&lt;T&gt; objects;
  </code></pre>
  
  <p>Can anyone help me pin point this error?</p>
  
  <p>Thanks,
  Y_Y</p>