title: Keep looping until user enters a blank line?
body: <p>So I've run into the following problem. My goal is to create a loop that keeps taking user input over and over until the user doesn't enter anything into 'cin >>', leaves the line blank, and simply presses the ENTER key to move on, at which point the program is supposed to break out of the loop and continue on with the rest of program execution. Something like this:</p>
  
  <pre><code> do { 
      cout &lt;&lt; "\nEnter a name: ";
      cin &gt;&gt; input1;
      if (input1.empty())
      {
          break;
      }
      else
      {
          user_name = input1;
      }
     } while (!input1.empty());
  </code></pre>
  
  <p>As you can see, I've already tried using the empty() function, but that didn't work, the program simply stays in the loop and doesn't break out, no matter how many times I press enter. It just keeps prompting me to enter a name. I've also tried using something like</p>
  
  <pre><code>if (input1 == "")
  </code></pre>
  
  <p>but that doesnt work either. Can anyone help? How do I break out of this loop?</p>
  
  <p><strong>UPDATE:</strong> OK guys, I've tried your recommendations, and it worked! Thank you so much! Unfortunately, although the getline function works, it has also created a new problem for me. Basically, in the first initial loop, the program prompts for a name, I type in a name, and the name is stored in user_name. However, in the SECOND loop, the program doesn't even give me the chance to enter any input, it simply prints "Enter a name: ", and then instantly exits out of the loop, and continues on with the rest of program execution. Why is this happening?</p>