title: Vector iterator not dereferencable in for loop
body: <p>I'm using a loop to count how many times that a word was entered then print the word and how many times it was entered, which works but it never prints the last word, I have it sorted alphabetically. Before the last word is printed it errors out saying the iterator is not dereferencable. Here is my code for the loop:</p>
  
  <pre><code>for (vector&lt;string&gt;::iterator it = v.begin() ; it != v.end(); ++it)
      {
          if (*it == *(it+1))
          {
          count++;
          }
          else if (*it != *(it+1))
          {
                  count++;
              cout &lt;&lt; *it &lt;&lt; " ---- " &lt;&lt; count &lt;&lt; endl;
              count=0;
          }
      }
  </code></pre>