title: use of: while (cin >> x) and eof
body: <p>I am not so sure how the  works I suppose is my root problem here. I've read a few previous posts on while(cin>>x) but nothing seems to answer my question really.
  I am using this loop to read in some text data:</p>
  
  <pre><code>while (cin &gt;&gt; x){
      searchText.push_back(x);
  }
  </code></pre>
  
  <p>but then later in the code I am trying to read in a single word using:</p>
  
  <pre><code>cout &lt;&lt; "Please enter your target word: ";
  string targetWord;
  cin &gt;&gt; targetWord;
  </code></pre>
  
  <p>but the above while loop/ eof seems to scupper the 2nd code snippet (if I move the 2nd code snippet up above it all works fine, but obviously that is not what im trying to do) </p>
  
  <p><em>EDIT</em>
  Here is the full code for clarity:</p>
  
  <pre><code>int main()
  {
  // ask for the target word
  //   cout &lt;&lt; "Please enter your target word: ";
  //   string targetWord;
  //   cin &gt;&gt; targetWord;
  
     // ask for and read the search text
     cout &lt;&lt;  "Enter the complete search text, "
              "followed by end-of-file: ";
     vector&lt;string&gt; searchText;
     string x;
     while (cin &gt;&gt; x){
        searchText.push_back(x);
     }
  
     // check that some text was entered
     typedef vector&lt;string&gt;::size_type vec_sz;
     vec_sz size = searchText.size();
     if (size == 0){
        cout &lt;&lt; endl &lt;&lt;   "You must enter some text. "
                          "Please try again." &lt;&lt; endl;
        return 1;
     }
  
  // ask for the target word
     cin.clear();
     cout &lt;&lt; "";
     cout &lt;&lt; "Please enter your target word: ";
     string targetWord;
     cin &gt;&gt; targetWord;
  
  
     int count = 0;
     for (int i=0; i&lt;size; ++i){
        if (targetWord == searchText[i]){
        count++;
        }
     }
  
     cout  &lt;&lt; "The target word [" &lt;&lt; targetWord &lt;&lt; "] was "
              "in the search text " &lt;&lt; count &lt;&lt; " times." &lt;&lt; endl;
  
     return 0;
  }
  </code></pre>
  
  <p>I am just trying to take in some text from the user... then a search word and see how many times the word appears in the entered text (pretty simple!) </p>
  
  <p>I know I could do it differently but the question here is more about how can I use the cout/ cin stream again after it has had an EOF in it previously </p>