title: Dereferencing iterator behavior in C++
body: <p>I'm trying to figure out why dereferencing the empty list iterator is preventing the rest of the code from running.   Comment out the line and everything seems fine, but leave it in and the program doesn't seem to get past that point.</p>
  
  <p>I guess it's supposed to be an error since the list is empty, but I'm not getting any warnings or errors.</p>
  
  <p>I'm using codeblocks with MinGW</p>
  
  <pre><code>    std::list&lt;std::string&gt; slist;
      std::string word;
  
      auto iter = slist.begin();
  
      //what is this doing?
      std::cout &lt;&lt; (*iter) &lt;&lt; std::endl;
  
      while(std::cin &gt;&gt; word)
      {
          iter = slist.insert(iter, word);
      }
  
      slist.insert(slist.begin(), {"foo", "bar"});
      for(auto item: slist)
          std::cout &lt;&lt; item &lt;&lt; std::endl;
  </code></pre>