title: why istream,ostream,iostream,ios_base all work here
body: <pre><code>int main()
  {
  int a=0;
  int b=0;
  std::cout&lt;&lt;"Please enter an int: "&lt;&lt;std::endl;
  std::cin&gt;&gt;a;
  auto old_state =std::cin.rdstate(); // remember the current state of cin
  std::cin.clear(); // make cin valid
  std::cout&lt;&lt;"Please enter another int: "&lt;&lt;std::endl;
  std::cin&gt;&gt;b;// use cin
  auto new_state = std::cin.rdstate();
  if(old_state==std::istream::failbit&amp;&amp;new_state==std::istream::failbit) 
  //I tried std::ostream,std::iostream,ios_base they all work.
  std::cout&lt;&lt;"Both are failbit!"&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>I just came across IO chapter on C++ Primer. I tried this code myself, and suprisingly found out that for the last two lines, I changed <code>std::istream</code> to <code>std::ostream</code>, <code>std::iostream</code>, <code>std::ios_base</code>, they all seems work when I typed in two <code>char</code>. Someone please help to explain this in plain words why could this happen. Many thanks in advance!</p>