title: C++ const std::map reference fails to compile
body: <p>Is there a reason why passing a reference to a <code>std::map</code> as const causes the [] operator to break? I get this compiler error (gcc 4.2) when I use const:</p>
  
  <blockquote>
    <p>error: no match for ‘operator[]’ in
    ‘map[name]’</p>
  </blockquote>
  
  <p>Here's the function prototype:</p>
  
  <pre><code>void func(const char ch, std::string &amp;str, const std::map&lt;std::string, std::string&gt; &amp;map);
  </code></pre>
  
  <p>And, I should mention that there is no problem when I remove the <code>const</code> keyword in front of <code>std::map</code>.</p>
  
  <p>If I've been instructed correctly, the [] operator will actually insert a new pair into the map if it doesn't find the key, which would of course explain why this happens, but I can't imagine that this would ever be acceptable behavior.</p>
  
  <p>If there is a better method, like using <em>find</em> instead of [], I'd appreciate it. I can't seem to get find to work either though... I receive <em>const</em> mismatched iterator errors.</p>