title: C++ - cin.get() requires user to press enter twice
body: <p>In my code I added an <code>if</code> statement which captures an empty string if the user accidentally presses the "enter" key. Without this piece of code the program will crash, below is the link to the screenshot:</p>
  
  <p><a href="http://gyazo.com/59cfe26c76043022b807d533f932838d" rel="nofollow">http://gyazo.com/59cfe26c76043022b807d533f932838d</a></p>
  
  <p>Since I added the code, the program works fine should a user press the "enter" key and will no longer crash - however, the code now makes the user have to press the "enter" key twice before the program moves forward.</p>
  
  <p>Below is the whole code, the <code>cin.get()</code> is on line 30, I will comment it out using <code>/*</code> to make it easier for you.</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;cstdlib&gt;
  #include &lt;algorithm&gt;
  #include &lt;string&gt;       // std::string
  #include &lt;locale&gt;       // std::locale, std::isalpha
  #include &lt;iostream&gt;     // std::cout
  using namespace std;
  
  int main(int nNumberofArgs, char* pszArgs[])
  {
      std::locale loc;        // This enables isalpha to be used
      std::string original;
      std::string new_word;
      bool alphaString = true; // A boolean data type variable assigned to true 
      std::string pyg = "ay";
      std::cout &lt;&lt; "(c) Copyright 2013 by Neeraj Morar. All Rights Reserved.\n";
      std::cout &lt;&lt; "\n"; 
      std::cout &lt;&lt; "Welcome to the English to PigLatin translator!\n";
      std::cout &lt;&lt; "You can exit the program at any time by closing the window.\n";
      std::cout &lt;&lt; "\n";
      while (true) {
          std::cout &lt;&lt; "Type a word you wish to translate:\n";
          std::getline(std::cin, original); // This allows the computer to capture the whole of the string input
          /*if (cin.get() == '\n')
          {
              std::cout &lt;&lt; "Please enter a word. (Remember to type in only ONE word!)\n";
              std::cout &lt;&lt; "\n" &lt;&lt; std::endl;
              alphaString = false;
              continue;
          }*/
          for (std::string::iterator it=original.begin(); it!=original.end(); ++it) // For loop testing string input (only used for the isalpha function)
          {
              if (! std::isalpha(*it,loc) &amp;&amp; original.length() &gt; 0) // If statement to test if string input is alpha characters is false
              {
                  std::cout &lt;&lt; "Please enter a valid word. (Remember to type in only ONE word!)";
                  std::cout &lt;&lt; "\n" &lt;&lt; std::endl;
                  alphaString = false; // Boolean variable set to false for if statement and outputs above string if non-alpha characters are found
                  break;
              }
          }
          if (alphaString) // Another if statement if string validates as true
          {
              std::transform(original.begin(), original.end(), original.begin(), ::tolower); // Converts string to lower case
              std::string first;
              first = original[0]; // [0] selects the first character of a string in the variable 'original'
              if (first == "a" || first == "e" || first == "i" || first == "o" || first == "u") // This if statement queries whether the first letter of a string consists of a vowel
              {
                  new_word = original + pyg; // This variable is a combination of the users' input and a variable called 'pyg' which consists of the string "ay"
                  std::cout &lt;&lt; "\n";
                  std::cout &lt;&lt; "Translation: " &lt;&lt; new_word &lt;&lt; "\n";
                  std::cout &lt;&lt; "\n";
              }
              else // This else statement is for strings that do not have a vowel as their first letter
              {
                  new_word = original.substr(1) + original[0] + pyg; // This variable is a combination of the original word starting from the 2nd character, the first letter of the string added on and then the var "pyg" added on at the end
                  std::cout &lt;&lt; "\n";
                  std::cout &lt;&lt; "Translation: " &lt;&lt; new_word &lt;&lt; "\n";
                  std::cout &lt;&lt; "\n";
              }
          }
      }
  
      system("PAUSE");
      return 0;
  }
  </code></pre>