title: cin in a while-loop
body: <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      string previous;
      string current;
  
      while (cin &gt;&gt; current)
      {
          if(current == previous)
          {
              cout &lt;&lt; "repeated word";
          }
  
          previous=current;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>my questions are: </p>
  
  <ol>
  <li><p>When it states <code>while(cin&gt;&gt;current)</code>, why is the entire entered string of text not assigned to current? I don't understand how it compares all the words individually. </p></li>
  <li><p>How does it get a word for previous. How does it know 2 of the same words are adjacent?</p></li>
  </ol>
  
  <p>EDIT: I think I just understood why. Tell me if I am wrong but I think its because the compiler stops the <code>cin</code> assignment at the space and that first word is assigned to current, then it compares it to the previous word, but since it is the first word, it does not have a previous word so it just assigned the first word to previous and compares the next word in the sentence until there are no more words left. I'm fairly certain this is how it works but I am going to leave this up in case anyone is ever wondering something similar. </p>