title: getline() function reading in whitespace before input is entered
body: <p>Alright, I wrote a game of hangman. The game works great, except after the user finishes the game, and enters the char value of Y to play again.</p>
  
  <p>I have traced the problem down to the getline() function at the start of my do-while loop. If I enter Y, then the do-while loop succesfully repeats, but the getline function seems to already think that there is input in cin, even though I don't enter anything.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  
  using namespace std;
  
  int main() {
  
  
  
  
  
      string secretWord;
      string secretWordClean = "";
      string guessedLetters; //to be loaded with _ characters equal to length of secretWord
      string incorrectlyGuessedChars = "";
      char individualCharGuess;
      char playAgain;
      size_t countOfLetters = 0; //begine count at 0
      size_t guessesRemaining;
      int guessedUsed;
  
  
      begin_game://label which we can use to bring us back to the start of the do-while loop at any time
  
      do{//start of the game
  
      cout &lt;&lt; "Please enter a secret word: ";
      getline(cin, secretWord); //y getline is cuaing the issue
  
  
       for(int i = 0; i &lt; secretWord.length(); i++){
              if (isalpha(secretWord[i])){ 
                      secretWordClean += secretWord[i];
              }
          }
  
       secretWord = secretWordClean; //assign all alpha secret word string back to original variable for better readability
       guessesRemaining = secretWord.length() * 2;
  
       for(int i = 0; i &lt; secretWord.length(); i++){
           guessedLetters += "_"; //fills guessedLetters with blanks equal to the length of the secretWord
       }
  
  
  
  
           cout &lt;&lt; "Please guess a letter, you have " &lt;&lt; guessesRemaining &lt;&lt; " guesses remaining!" &lt;&lt; endl;
           cin &gt;&gt; individualCharGuess;
  
           for(int i = 0; i &lt; secretWord.length(); i++){ //every complete iteration of this for loop = one single guess
                  if(secretWord[i] == individualCharGuess){
                      guessedLetters[i] = individualCharGuess; //will replace the spaces with the correct character, if guessed
                      countOfLetters++; //if any letter is guessed correctly, this indicator will be inrimented above 0
                      continue;
                   }
  
                  if(secretWord.find(individualCharGuess) == string::npos){
                      if(incorrectlyGuessedChars.find(individualCharGuess) == string::npos){
                      incorrectlyGuessedChars += individualCharGuess;
                      }
                  }
           }
  
           if(secretWord.compare(guessedLetters) == 0){
               cout &lt;&lt; "You win! The word was: " &lt;&lt; secretWord &lt;&lt; endl;
               guessedUsed = ((secretWord.length() * 2) - guessesRemaining) + 1 ;
               cout &lt;&lt; "You used " &lt;&lt; guessedUsed &lt;&lt; " guesses." &lt;&lt; endl; 
               cout &lt;&lt; "Play again? Enter Y for Yes, or anything else to exit: ";
               cin &gt;&gt; playAgain;
               if(playAgain != 'Y'){
               break; //exit the loop if user guesses all the letters and doesn't want to play again
               }
               else {
                   goto begin_game;
               }
           }
  
           guessesRemaining--; //we decriment our total guesses remaining if the user does not win the game or run out of guesses
  
           if(countOfLetters &gt; 0){
               cout &lt;&lt; "You have correctly guessed a letter!" &lt;&lt; endl;
               cout &lt;&lt; "Here are the letters you have guessed correctly so far: ";
               cout &lt;&lt; guessedLetters &lt;&lt; endl;
               cout &lt;&lt; "Here are the letters you have guessed incorrectly so far: ";
               cout &lt;&lt; incorrectlyGuessedChars &lt;&lt; endl;
               countOfLetters = 0; //reset the counter to prepare for next iteration of do-while loop
           }
           else if (guessesRemaining &lt;= 0) {
               cout &lt;&lt; "You have run out of guesses!" &lt;&lt; endl;
               cout &lt;&lt; "Here are the letters that you guessed correctly: ";
               cout &lt;&lt; guessedLetters &lt;&lt; endl;
               cout &lt;&lt; "Here are the letters you guessed incorrectly: ";
               cout &lt;&lt; incorrectlyGuessedChars &lt;&lt; endl;
               cout &lt;&lt; "The secret word was: " &lt;&lt; secretWord &lt;&lt; endl;
               cout &lt;&lt; "Play again? Enter Y for Yes, or anything else to exit: ";
               cin &gt;&gt; playAgain;
               if(playAgain != 'Y'){
               break; //exit the loop if user guesses all the letters and doesn't want to play again
               }
               else goto begin_game;
           }
           else {
               cout &lt;&lt; "You guessed wrong! Keep trying, " &lt;&lt; guessesRemaining &lt;&lt; " guesses to go!" &lt;&lt; endl;
               cout &lt;&lt; "Here are the letters you have guessed correctly so far: ";
               cout &lt;&lt; guessedLetters &lt;&lt; endl;
               cout &lt;&lt; "Here are the letters you have guessed incorrectly so far: ";
               cout &lt;&lt; incorrectlyGuessedChars &lt;&lt; endl;
           }
  
  
  
       }while (secretWord.compare(guessedLetters) != 0 || guessesRemaining != 0); //use to repeat the request for a single char guess
  
  
      return 0;
  }
  </code></pre>