title: Is there a way to check if an istream was opened in binary mode?
body: <p>I'm using an istream which could be stringstream, ifstream or a user-defined stream type and I need to know if, in the case of an ifstream, it was not opened in binary mode (so I can throw an exception). I have tried the following method:</p>
  
  <pre><code>if ((_is.flags() &amp; ios::binary) == 0)
      throw exception(...)
  </code></pre>
  
  <p>but no exception is ever thrown. The test fails in this case because _is.flags() returns 0x201 and ios::binary is 0x20. Is there a way to find out if a stream was opened in text mode?</p>