I'm trying to pass a C++ map by reference to a function and iterate through it but I cannot compile the code
<p>I have a fairly simple problem. I'm trying to make a function that accepts a map by reference and iterates through the keys of the map.</p>

<pre><code>#include &lt;map&gt;
#include &lt;string&gt;
#include &lt;sys/types.h&gt;

using namespace std;

void update_fold_score_map(string subfold,
                           int32_t index,
                           int32_t subfold_score,
                           map&lt;string, int32_t&gt; &amp;fold_scores){
  for(map&lt;string, int32_t&gt;::iterator i = fold_scores.begin();
      i != fold_scores.end();
      i ++){
    string current_substring;
    string fold;
    fold = (*i);
    current_substring = fold.substr(index, subfold.size());

    if (current_substring == subfold){
      if (fold_scores[fold] &lt; subfold_score){
        fold_scores[fold] = subfold_score;
      }
      return;
    }
  }
}
int main(){
  return 0;
}
</code></pre>

<p>But, I'm getting an error at the line "fold = (*i);" which states:</p>

<pre><code>compilemap.cpp:16:15: error: no match for ‘operator=’ in ‘fold = i.std::_Rb_tree_iterator&lt;_Tp&gt;::operator* [with _Tp = std::pair&lt;const std::basic_string&lt;char&gt;, int&gt;, std::_Rb_tree_iterator&lt;_Tp&gt;::reference = std::pair&lt;const std::basic_string&lt;char&gt;, int&gt;&amp;]()’
</code></pre>
