title: Segfault in map
body: <p>I can't understand why does this code fail with segfault:</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main(int argc, char** argv) {
  
      map &lt;string, string&gt; temp;
      map &lt;string, string&gt;::iterator it;
  </code></pre>
  
  <p>S<br>
          string text = "";
          string thatChange = "";
          string whatChange = "";</p>
  
  <pre><code>    getline (cin, text);
  
  
      while (true)
      {
          getline (cin, thatChange);
          if (thatChange == "-1")
              break;
  
          getline (cin, whatChange);
          temp.insert(pair &lt;string, string&gt; (thatChange, whatChange));
      }
  
      for (int i = 0; i &lt; temp.size(); i++)
      {
          string thatChange = it-&gt;first ; // thatChange
          string whatChange = it-&gt;second; // whatChange
          it++;
  
          int index = text.find(thatChange);
          text.erase(index, thatChange.size());
          text.insert(index, whatChange);
      }
  
      cout &lt;&lt; "text\n"&lt;&lt; text;
  
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>UPD:
  Debugger says:</p>
  
  <pre><code>No source available for "std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string() at 0x7ffff7b75928" 
  </code></pre>