title: How can I get a cin loop to stop upon the user hitting enter?
body: <p>Here's my C++ code right now:</p>
  
  <pre><code>// Prompt user loop
  char preInput;
  do {
      // Fill the vector with inputs
      vector&lt;int&gt; userInputs;
      cout &lt;&lt; "Input a set of digits: " &lt;&lt; endl;
      while(cin&gt;&gt;preInput){
          if(preInput == 'Q' || preInput == 'q') break;
          int input = (int) preInput - '0';
          userInputs.push_back(input);
      }       
  
      // array of sums sync'd with line #
      int sums[10] = {0};
  
      // Calculate sums of occurance
      for(vector&lt;int&gt;::iterator i = userInputs.begin(); i != userInputs.end(); i++){
          int currInput = *i;
          for(int numLine = 0; numLine &lt; lines.size(); numLine++){
              sums[numLine] += lineOccurances[numLine][currInput];
          }
      }
  
      int lineWithMax = 0;
      for(int i = 0; i &lt; 10; i ++)        
          if(sums[i] &gt; sums[lineWithMax]) lineWithMax = i;
  
      cout &lt;&lt; lines[lineWithMax] &lt;&lt; endl;
  
      // Clear vector
      userInputs.clear();
  } while (preInput != 'Q' &amp;&amp; preInput != 'q')
  </code></pre>
  
  <p>Don't worry about the function of the loop, I just need it to run in a certain way.
  If a user types in "123" the loop should load the chars 1,2,3 into userInputs as separate elements.
  Upon hitting enter, the loop needs to execute all of the code below the while(cin>>preInput){} statement, clear the userInput vector, and repeat until the character Q is entered.  This is not what's happening.  The way the loop is currently written, The program takes user input until the user hits Q, enter essentially does nothing.  I need the code to execute whenever the user hits enter.  I've been playing with this for a while but I'm not too familiar with taking data through a char into a vector via cin so I'm not sure how to do this...Can anyone point me in the right direction?</p>
  
  <p>Would changing the cin>>preInput to a getline work? Or would this attempt to put the value say..."123" into the char preInput as one assignment?  I need the vector to receive the numbers separately rather than all together as one element. To reiterate, if the user enters "123" userInputs[0] should be 1, userInputs[1] should be 2...and so on.</p>
  
  <p>Essentially, the only thing that needs to be changed is that the while(cin>>preInput){} loop must break when the user hits enter.</p>