title: C++ Detecting ENTER key pressed by user
body: <p>I have a loop where I ask the user to enter a name. I need to stop when the user presses the ENTER key..... or when 20 names have been entered. However my method doesn't stop when the user presses the ENTER key</p>
  
  <pre><code>//loop until ENTER key is entered or 20 elements have been added
  bool stop = false;
  int ind = 0;
  while( !stop || ind &gt;= 20 ){
  
      cout &lt;&lt; "Enter name #" &lt;&lt; (ind+1) &lt;&lt; ":";
      string temp;
      getline(cin, temp);
      int enterKey = atoi(temp.c_str());        
  
      if(enterKey == '\n'){
          stop = true;            
      }
      else{
          names[ind] = temp;
      }
  
      ind++;
  
  
  }
  </code></pre>