title: C++ STL: Trouble with string iterators
body: <p>I'm making a simple command line Hangman game.</p>
  
  <pre><code>void Hangman::printStatus()
  {
      cout &lt;&lt; "Lives remaining: " &lt;&lt; livesRemaining &lt;&lt; endl;
      cout &lt;&lt; getFormattedAnswer() &lt;&lt; endl;
  }
  
  string Hangman::getFormattedAnswer()
  {
      return getFormattedAnswerFrom(correctAnswer.begin(), correctAnswer.end());
  }
  
  string Hangman::getFormattedAnswerFrom(string::const_iterator begin, string::const_iterator end)
  {
      return begin == end? "" : displayChar(*begin) + getFormattedAnswerFrom(++begin, end);
  }
  
  char Hangman::displayChar(const char c)
  {
      return c;
  }
  </code></pre>
  
  <p>(Eventually, I'll change this so <code>displayChar()</code> displays a <code>-</code> or a character if the user has guessed it, but for simplicity now I'm just returning everything.)</p>
  
  <p>When I build and run this from VS 2010, I get a popup box:</p>
  
  <blockquote>
    <p>Debug Assertion Failed!</p>
    
    <p>xstring Line: 78</p>
    
    <p>Expression: string iterator not
    dereferenceable</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>