title: Reuse std::cin after eating an EOF
body: <p>The unix command <code>wc</code> has this functionality:</p>
  
  <pre><code>$ wc - - -
  aaa bbb ccc&lt;EOF&gt;
  0 3 11 -
  aaa bbb ccc&lt;EOF&gt;
  0 3 11 -
  aaa bbb ccc&lt;EOF&gt;
  0 3 11 -
  0 9 33 total
  </code></pre>
  
  <p>Each <code>&lt;EOF&gt;</code> indicates a <code>&lt;C-d&gt;</code> key sequence that enters an <code>EOF</code> into stdin. wc is then able to pick up this <code>EOF</code>.</p>
  
  <p>I'm trying to implement this in C++. A common suggestion is  combination of <code>clear()</code> and <code>ignore()</code>.</p>
  
  <pre><code>char c;
  while (std::cin &gt;&gt; c) { ... }
  
  std::cin.clear();
  std::cin.ignore();
  
  while (std::cin &gt;&gt; c) { /* never executed */ }
  </code></pre>
  
  <p>I've also tried <code>std::cin.peekg(std::cin.beg)</code>, which also does not work.</p>