title: Introduction To C++ IO Streams
body: <p>I got a snippet of code from <a href="http://www.cprogramming.com/tutorial/c++-iostreams.html" rel="nofollow">this article</a> and I'm confused as to how it works? The snippet starts by saying:</p>
  
  <blockquote>
    <p>You can detect that a particular read or write operation failed by testing the result of the read. For example, to check that a valid integer is read from the user, you can do this:</p>
  </blockquote>
  
  <pre><code>int x;
  if ( cin &gt;&gt; x ) 
  {
      cout &lt;&lt; "Please enter a valid number" &lt;&lt; endl;
  }
  </code></pre>
  
  <blockquote>
    <p>This works because the read operation returns a reference to the stream.</p>
  </blockquote>
  
  <p>I understand that the cin >> x operation returns a reference to cin but I'm still confused as to how evaluating the reference to the standard input stream object allows you to check that the input is a valid integer.</p>