title: Accessing map value by index
body: <p>If I have a structure like</p>
  
  <pre><code>std::map&lt;string, int&gt; myMap;
  myMap["banana"] = 1;
  myMap["apple"] = 1;
  myMap["orange"] = 1;
  </code></pre>
  
  <p>How can I access myMap[0]?</p>
  
  <p>I know that the map sorts internally and I'm fine with this, I want to get a value in the map by index. I've tried myMap[0] but I get the error:</p>
  
  <pre><code>Error   1   error C2679: binary '[' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)   
  </code></pre>
  
  <p>I realise I could do something like this:</p>
  
  <pre><code>string getKeyAtIndex (int index){
      map&lt;string, int&gt;::const_iterator end = myMap.end(); 
  
      int counter = 0;
      for (map&lt;string, int&gt;::const_iterator it = myMap.begin(); it != end; ++it) {
          counter++;
  
          if (counter == index)
              return it-&gt;first;
      }
  }
  </code></pre>
  
  <p>But surely this is hugely inefficient? Is there a better way? </p>