title: How to read cin into a vector
body: <p>I need to allow the user to enter a writing sample in the console or as a file and have my program split that input into a word vector (one word per item of vector). This is my current code:</p>
  
  <pre><code>while(cin &gt;&gt; inputString) {
      wordVector.push_back(inputString);
  }
  </code></pre>
  
  <p>The trouble is, when I run this, it works fine until it reaches the end of the user's input. Then it seems to just endlessly loop. </p>
  
  <p>inputString is type string.</p>
  
  <p>wordVector is type string.</p>
  
  <p>This is the full code: (the broken code is at the bottom)</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  // Debug message flag
  const bool DEBUG = false;
  
  // Prototypes
  void splitToVectors(vector&lt;string&gt;&amp;,vector&lt;string&gt;&amp;,vector&lt;int&gt;&amp;,int &amp;);
  double avSentLength(const vector&lt;string&gt;);
  double avWordSyl(const vector&lt;string&gt;,const vector&lt;char&gt;);
  double percentSentLong(const vector&lt;int&gt;,int);
  int numSyllables(const vector&lt;char&gt;);
  void nextScreen(int);
  
  int main() {
  
      // Initialize variables and vectors
      bool validate;
      int characters,words,sentences = 0,syllables;
      string file;
      string inputString;
      char inputChar;
      int input;
  
      vector&lt;string&gt; wordVector;
      vector&lt;char&gt; charVector;
      vector&lt;string&gt; sentenceVector;
      vector&lt;int&gt; numWordsInSent;
  
      // Get writing sample
      do {
  
          // Request preferred location
          validate = true;
          cout &lt;&lt; "Would you like to:" &lt;&lt; endl;
          cout &lt;&lt; "  1. Enter the writing sample in the console" &lt;&lt; endl;
          cout &lt;&lt; "  2. Read from a file" &lt;&lt; endl &lt;&lt; " &gt; ";
  
          // Validate
          if(!(cin &gt;&gt; input)) { // This error checking condition functions as the cin
              validate = false;
              cin.clear();
              cin.ignore(100, '\n');
          }
          if((input &lt; 1) || (input &gt; 2)) {
              validate = false;
      }
  
      } while(!validate);
  
  
      // Transfer selected source to wordVector
      if(input == 1) {
  
          // Request sample
          cout &lt;&lt; "Please enter the writing sample below:" &lt;&lt; endl &lt;&lt; endl;
  
          // Input sample
          while(cin &gt;&gt; inputString) {
              wordVector.push_back(inputString);
          }
      }
  }
  </code></pre>