title: Detect hitting Enter Key in C++
body: <p>How can I get my code to detect me hitting the enter key? I tried using <code>cin.get()</code> without any success. Also when the enter key is pressed, I'd like to change a boolean x from true to false.</p>
  
  <p>Why doesn't this work?</p>
  
  <pre><code>if (cin.get() == '\n'){
  x = false;
  }
  </code></pre>
  
  <p>I'd like to end my loop (and thus and the program) when the enter key is pressed (see code below)</p>
  
  <p>All code (simple rock, paper, scissors game):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cstdlib&gt; //random
  #include &lt;time.h&gt; //pc time
  
  using namespace std;
  
  int main()
  {
  
      string rpsYou;
      string rpsCom;
      string winner;
      bool status = true;
  
  while (status){
      cout &lt;&lt; "Welcome to Rock, Scissors, Paper!\nYou'll have to compete against the computer."
              " Please enter 'Rock', 'Paper' or 'Scissors' here: ";
      cin &gt;&gt; rpsYou;
  
      //Random number
      srand (time(NULL));
  int randomNum = rand() % 4; //  -&gt; (rand()%(max-min))+min;
  
  //Computers guess
  if (randomNum ==1){
      rpsCom = "Rock";
  }
  else if (randomNum ==2){
      rpsCom = "Paper";
  }
  else {
      rpsCom = "Scissors";
  }
  
  //First letter to capital
  rpsYou[0] = toupper(rpsYou[0]);
  
  if (rpsYou == "Rock" || rpsYou == "Paper" || rpsYou == "Scissors"){
  
      cout &lt;&lt; "You: " &lt;&lt; rpsYou &lt;&lt; "\nComputer: " &lt;&lt; rpsCom &lt;&lt; "\n";
  
  }
  else {
      cout &lt;&lt; "ERROR: Please enter 'Rock', 'Paper' or 'Scissors'.";
  }
  
  
  if ( (rpsYou == "Rock" &amp;&amp; rpsCom == "Rock") ||
       (rpsYou == "Paper" &amp;&amp; rpsCom == "Paper") ||
       (rpsYou == "Scissors" &amp;&amp; rpsCom == "Scissors") ){
  
      cout &lt;&lt; "Tie :|";
  
  }
  else if( (rpsYou =="Rock" &amp;&amp; rpsCom =="Scissors") ||
           (rpsYou =="Paper" &amp;&amp; rpsCom =="Rock") ||
           (rpsYou =="Scissors" &amp;&amp; rpsCom =="Paper")){
      cout &lt;&lt; "Congratulations! You won! :)";
  }
  
  else{
      cout &lt;&lt; "Oh no! You lost! :(";
  }
  
  }
  
      return 0;
  }
  </code></pre>