title: How to pass cin to a function?
body: <p>I am learning about different stream state flags/functions in C++ such as good(), goodbit, bad(), badbit and so on. While testing with std::cin, I am unable to pass cin as an argument to a function (the compiler shows a lot of errors)</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  
   void print_state (const std::istream&amp; stream) {
      std::cout &lt;&lt; " good()=" &lt;&lt; stream.good();
      std::cout &lt;&lt; " eof()=" &lt;&lt; stream.eof();
      std::cout &lt;&lt; " fail()=" &lt;&lt; stream.fail();
      std::cout &lt;&lt; " bad()=" &lt;&lt; stream.bad();
  } 
  
  int main() {
      std::cin.clear (std::ios::goodbit);
      std::cout &lt;&lt; "goodbit: " &lt;&lt; print_state(std::cin) &lt;&lt; std::endl;
  
      std::cin.clear (std::ios::eofbit);
      std::cout &lt;&lt; "eofbit: " &lt;&lt; print_state(std::cin) &lt;&lt; std::endl;
  
      std::cin.clear (std::ios::failbit);
      std::cout &lt;&lt; "failbit: " &lt;&lt; print_state(std::cin) &lt;&lt; std::endl;
  
      std::cin.clear (std::ios::badbit);
      std::cout &lt;&lt; "badbit: " &lt;&lt; print_state(std::cin) &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>goodbit: good()=1 eof()=0 fail()=0 bad()=0
   eofbit: good()=0 eof()=1 fail()=0 bad()=0
  failbit: good()=0 eof()=0 fail()=1 bad()=0
   badbit: good()=0 eof()=0 fail()=1 bad()=1
  </code></pre>
  
  <p>I know I can call the function directly with cin, such as <code>std::cin.good()</code>, but I want to know how can I pass cin as an argument to a function.</p>
  
  <p><strong>Edit:</strong>
  I get a LOT of errors during compilation. An example:</p>
  
  <pre><code>F:\cpp_programming\stream_states.cpp: In function 'int main()':
  F:\cpp_programming\stream_states.cpp:13:27: error: no match for 'operator&lt;&lt;' (operand types are 'std::basic_ostream&lt;char&gt;' and 'void')
    std::cout &lt;&lt; "goodbit: " &lt;&lt; print_state(std::cin) &lt;&lt; std::endl;
    ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
  </code></pre>