Removing duplicate elements of a vector of pairs based on individual elements inside the pair
<p>So I need to find some most common used words in a file.</p>

<p>I have a <code>vector&lt;pair&lt;string, int&gt; &gt; wordList</code> which keeps track of every word in the file along with its frequency. This part works fine.</p>

<p>The problem is, the output shows multiple versions of each word. This is because the way I calculated it was:</p>

<ul>
<li>load all words into the vector with a frequency of 1</li>
<li>Go through again and if the word shows up twice, increase its count</li>
<li><p>The part that I need help on, which is to delete multiple entries of the same word.</p>

<pre><code>for(int j = 0; j &lt; wordList.size(); j++)
{
</code></pre></li>
</ul>

<p>This is my current approach. This function tallys up all the word. the problem is that the line <code>wordList.erase</code> that's inside the for loop
produces an out of bounds error, so I cant remove the duplicate entry that way.
I also tried the unique() approach, but that doesn't seem to work it only removes some entries.</p>

<p>What is the most efficient way to reduce a vector of pairs to only unique elements?</p>