title: How to iterate through a multimap and print values grouped by key?
body: <p>I have <code>std::multimap&lt;string, MyObject*&gt; dataMap;</code> where the keys are <code>MyObject.name</code> and all MyObjects are stored in a <code>std::vector&lt;MyObject&gt;</code>.</p>
  
  <p>After filling the map I need to print the contents of <code>dataMap</code> grouped by the same key, where I first need number of same keys with the help of <code>dataMap.count(MyObject.name)</code> and then all the values with this key.</p>
  
  <p>I was thinking of using two <code>for loops</code> where the first loop iterates through "key group names" and counts all the keys that belong in this group, and the other <code>for loop</code> iterates through all the keys in certain group and prints the <code>MyObject.information</code></p>
  
  <pre><code>for(//iterate through group key names){
     //print number of key occurences
     for(//iterate through a certain group{
        //print MyObject.information for all the keys in a group
     }
  
  }
  </code></pre>
  
  <p>The problem is, i don't really know how would implement this or rather how would I use iterators to my will. Any ideas?</p>
  
  <p>EDIT: From the provided links i created this</p>
  
  <pre><code> for(std::multimap&lt;string, MyObject*&gt;::const_iterator itUnq = dataMap.cbegin();
       itUnq != dataMap.cend(); itUnq = dataMap.upper_bound(itUnq-&gt;first)){
  
          std::cout &lt;&lt; dataMap.count(itUnq-&gt;second-&gt;name)
                    &lt;&lt; std::endl;
  
          std::pair &lt;std::multimap&lt;string, MyObject*&gt;::const_iterator, 
                     std::multimap&lt;string, MyObject*&gt;::const_iterator&gt; groupRange;
          groupRange = dataMap.equal_range(itUnq-&gt;second-&gt;code);
  
          //iterate through keys inside the group
          for(std::multimap&lt;string, MyObject*&gt;::const_iterator itGroup = groupRange.first;
              itGroup != groupRange.second; ++itGroup){
  
              std::cout &lt;&lt; itGroup-&gt;second-&gt;information
  
          }
  </code></pre>
  
  <p>Comments?</p>