title: C++ Read File Into hash_map
body: <p>I'm trying to read in a list of words and save them in a C++ STL hash_map along with their position in the alphabetically sorted file. The idea is later I'll need to be able to tell if a string is a word and whether it comes before or after a different word. </p>
  
  <pre><code>ifstream f_dict ("dictionary.txt");
  __gnu_cxx::hash_map &lt;const char*, int&gt; dictionary;
  string temp_str;
  int counter = 0;
  while (!f_dict.eof()) {
      f_dict &gt;&gt; temp_str;
      dictionary.insert(make_pair(temp_str.c_str(), counter++));
  }
  </code></pre>
  
  <p>The problem I'm having is that it isn't saving the actual word. The <code>for loop</code> below prints out a selection of the words, but <code>iter-&gt;first</code> is always empty. What am I missing?</p>
  
  <pre><code>__gnu_cxx::hash_map&lt;const char*, int&gt;::iterator iter;
  int i = 0;
  for (iter = dictionary.begin(); iter != dictionary.end() &amp;&amp; i &lt; 150; iter++) {
      cout &lt;&lt; "word: " &lt;&lt; iter-&gt;first &lt;&lt; " index: " &lt;&lt; iter-&gt;second &lt;&lt; "\n";
      i++;
  }
  </code></pre>