title: Strange behavior of std::cin as while loop condition
body: <p>So...here is my code that refer to <em>C++ Primer</em> 1.4.4 section.</p>
  
  <pre><code>#include &lt;iostream&gt;
  int main()
  {
    int currVal = 0, val = 0;
    if (std::cin &gt;&gt; currVal) {
      int cnt = 1;
  
      while (std::cin &gt;&gt; val) {
        if (val == currVal) {
          ++cnt;
        } else {
          std::cout &lt;&lt; currVal &lt;&lt; " occurs "
                    &lt;&lt; cnt &lt;&lt; " times." &lt;&lt; std::endl;
          currVal = val;
          cnt = 1;
        }
      }
      std::cout &lt;&lt; currVal &lt;&lt; " occurs "
                &lt;&lt; cnt &lt;&lt; " times." &lt;&lt; std::endl;
    }
    return 0;
  }
  </code></pre>
  
  <p>I have to admit that the simple program basically work normally. But for the further discussion, I'd like refer to <a href="https://asciinema.org/a/194063" rel="nofollow noreferrer">a <code>asciinema</code> recording</a> in the first place.</p>
  
  <p>In the recording I run <code>./a.out</code> three times. In the first time, I typed numbers and press <kbd>enter</kbd> the first two recording printed and only after <kbd>ctrl</kbd> + <kbd>D</kbd> was pressed the third (last) result was printed. From previous sections in the book, I know <kbd>ctrl</kbd> + <kbd>D</kbd> is used to feed some symbols to stop the while loop. But I really wonder if it (<kbd>ctrl</kbd> + <kbd>D</kbd> here cause a strange stop) works just like as same as authors' expectation for there is no mention on how keys was pressed exactly about that example in the book.</p>
  
  <p>In the last two runs, my first approach is press <kbd>ctrl</kbd> + <kbd>D</kbd> (the first result printed) and <kbd>enter</kbd> (the second result printed), then following several <kbd>enter</kbd>s (no respond except more lines). Lastly, I pressed <kbd>ctrl</kbd> + <kbd>D</kbd> (the third result printed).</p>
  
  <p>My last approach is press <kbd>ctrl</kbd> + <kbd>D</kbd> for two times. The first result printed on the first press and the last two came out on the second press.</p>
  
  <p>With these two runs comes my confusing that after press <kbd>ctrl</kbd> + <kbd>D</kbd> (I think) there should be a stopping signal in the end of <code>cin</code> stream. So why did the <code>while</code> loop not stop? I'd appreciate a lot if anyone can explain the process behind it.</p>
  
  <p>My working environment is <code>urxvt</code> on <code>Manjaro Linux</code> with <code>zsh</code> and <code>oh-my-zsh</code> installed.</p>