title: Why doesn't uint8_t and int8_t work with file and console streams?
body: <pre><code>$ file testfile.txt
  testfile.txt: ASCII text
  
  $ cat testfile.txt 
  aaaabbbbccddef
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;cstdint&gt;
  typedef uint8_t byte; // &lt;-------- interesting
  typedef std::basic_ifstream&lt;byte&gt; FileStreamT;
  static const std::string FILENAME = "testfile.txt";
  int main(){
      FileStreamT file(FILENAME, std::ifstream::in | std::ios::binary);
      if(!file.is_open())
          std::cout &lt;&lt; "COULD NOT OPEN FILE" &lt;&lt; std::endl;
      else{
          FileStreamT::char_type buff;
          file.read(&amp;buff,1);
          std::cout &lt;&lt; (SOMECAST)buff; // &lt;------- interesting
      }
      std::cout &lt;&lt; "done" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Depending on what is in the typedef and what is it casted to (or not casted), it does all sorts of stupid things.</p>
  
  <p>It happens to work with 'typedef char' and no cast. (97 when casted to int, as expected)</p>
  
  <p>Both uint8_t and int8_t will print</p>
  
  <ul>
  <li><p>nothing without cast</p></li>
  <li><p>nothing when casted to char or unsigned char</p></li>
  <li><p>8 when casted to int or unsigned (although ASCII 'a' should be 97)</p></li>
  </ul>
  
  <p>I somehow managed to print a "�" character, but forgot which case it was.</p>
  
  <p>Why do I get these strange results?</p>
  
  <h2>notes for the future reader:</h2>
  
  <p>takeaway from the answer given: only instantiate streams with char (or one of the wide characters also mentioned by the standard), otherwise you get no compiler warning and silent failure</p>
  
  <p>it is very sad that the standard warrants these things</p>
  
  <h1>moral of the story: avoid C++</h1>