I am making my hangman clone and is stuck again in this function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int
word_handle::removeLetter( constchar c )
{
int flag = 0;
for ( std::string::iterator it = wordToGuess_.begin();
it != wordToGuess_.end();
++it )
{
if ( *it == c )
{
wordToGuess_.erase( it );
flag = 1; // there is a c in the string
}
}
return flag;
}
The problem is, for example, wordToGuess_ was "kangaroo", and the parameter was 'o', only one of 'o' in "kangaroo" is deleted, and if ever i remove one of 'o', in kangaroo, -> "kangaro", the program crashes ( BEX ) ?