title: How to insert pairs into a map based on user input and then find the element associated with a key given by user?
body: <p>The following code is not working if I add the part to find the element. Without that part, the 1st part of code is working to add and display elements of a <code>stl::map</code></p>
  
  <pre><code>    #include&lt;iostream&gt;
      #include&lt;map&gt;
      #include&lt;utility&gt;
  
      using namespace std;
  
      int main()
      {
          int n, k, q;
          char *v;
          map&lt;int, char*&gt; m1;
          map&lt;int, char*&gt;::iterator it;
          cout &lt;&lt; "enter number of elements\n";
          cin &gt;&gt; n;
          cout &lt;&lt; "enter number and string- \n";
          for(int i=0; i&lt;n; i++)
          {
              cin &gt;&gt; k;
              cin &gt;&gt; v;
              m1.insert(pair&lt;int, char*&gt;(k, v));
          }
          cout &lt;&lt; "elements are- " &lt;&lt; endl;
          for (it=m1.begin(); it!=m1.end(); it++)
              cout &lt;&lt; it-&gt;first &lt;&lt; " " &lt;&lt; it-&gt;second &lt;&lt; "\n";
  
      /* if the code is kept up to this and compiled,
         the map elements are displayed. If the following code is added
         to find the element, the application crashes just after taking
         an input to fill the map */
  
          cout &lt;&lt; "enter a key to find element\n";
          cin &gt;&gt; q;
          it = m1.find(q);
          if(it!=m1.end())
          cout &lt;&lt; it-&gt;first &lt;&lt; " " &lt;&lt; it-&gt;second ;
          else
              cout &lt;&lt; "key was not found\n";
  
          return 0;
      }
  </code></pre>