title: Why does reading of this stream from a binary file stop at the 0x1A character?
body: <p>I have found that 0x1A is Substitute but I am not sure what that means and why stream reading stops.  Also I would of course like to know how to fix the problem.</p>
  
  <p>To start with, I generate the binary file using this code:</p>
  
  <pre><code>unsigned char bytes[] = { 
      0xA1, 0x58, 0x02, 0x01, 0x03, 0x02, 0x01, 0x15, 0x30, 0x50, 0x55, 0x04, 0x02, 0x00, 0x00, 0x00, 
      0xA7, 0x48, 0xA0, 0x46, 0xA4, 0x44, 0xA7, 0x42, 0x04, 0x40, 0x8A, 0x00, 0x35, 0x2C, 0x77, 0x58, 
      0x83, 0xE9, 0x78, 0x9F, 0x4F, 0x34, 0x06, 0xE1, 0xB2, 0x57, 0x3A, 0x0C, 0xEF, 0x18, 0x54, 0x54, 
      0x1A, 0x4D, 0xBF, 0x2D, 0x02, 0x36, 0x18, 0xCB, 0x4A, 0xC3, 0x58, 0x20, 0xFC, 0x92, 0xDE, 0xBC, 
      0x85, 0x94, 0x90, 0x27, 0x36, 0x05, 0xEA, 0xE5, 0xEA, 0xE6, 0x0B, 0x73, 0xEF, 0xD1, 0x9E, 0x85, 
      0x38, 0x57, 0x1E, 0xF6, 0x62, 0x9B, 0x8F, 0x74, 0xA3, 0x00 };
  
  const size_t sz = sizeof(bytes) / sizeof(bytes[0]);
  
  std::ofstream fstrm("binfile.bin", std::ofstream::binary);
  std::for_each(bytes, bytes + sz, [&amp;](const char ch) {
      fstrm.put(ch);
  });
  fstrm.close();
  </code></pre>
  
  <p>Then I am using the C++ std lib IO functions to read the stream as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iterator&gt;     // std::istream_iterator
  #include &lt;algorithm&gt;
  
  
  int main() {
  
      unsigned char bytes[] = {
          0xA1, 0x58, 0x02, 0x01, 0x03, 0x02, 0x01, 0x15, 0x30, 0x50, 0x55, 0x04, 0x02, 0x00, 0x00, 0x00,
          0xA7, 0x48, 0xA0, 0x46, 0xA4, 0x44, 0xA7, 0x42, 0x04, 0x40, 0x8A, 0x00, 0x35, 0x2C, 0x77, 0x58,
          0x83, 0xE9, 0x78, 0x9F, 0x4F, 0x34, 0x06, 0xE1, 0xB2, 0x57, 0x3A, 0x0C, 0xEF, 0x18, 0x54, 0x54,
          0x1A, 0x4D, 0xBF, 0x2D, 0x02, 0x36, 0x18, 0xCB, 0x4A, 0xC3, 0x58, 0x20, 0xFC, 0x92, 0xDE, 0xBC,
          0x85, 0x94, 0x90, 0x27, 0x36, 0x05, 0xEA, 0xE5, 0xEA, 0xE6, 0x0B, 0x73, 0xEF, 0xD1, 0x9E, 0x85,
          0x38, 0x57, 0x1E, 0xF6, 0x62, 0x9B, 0x8F, 0x74, 0xA3, 0x00 };
  
      const size_t sz = sizeof(bytes) / sizeof(bytes[0]);
  
      std::cout &lt;&lt; "cout with array\n";
      std::for_each(bytes, bytes+sz, [](unsigned char ch) {
          std::cout &lt;&lt; std::hex &lt;&lt; (int)ch &lt;&lt; ' ';
      });
      std::cout &lt;&lt; "\n\n";
  
      std::istream_iterator&lt;unsigned char&gt; eos;              // end-of-stream iterator
      std::istream_iterator&lt;unsigned char&gt; iit(std::cin);   // stdin iterator
  
      std::cout &lt;&lt; "cout with stdin - redirecting file of same bytes as above\n";
      std::for_each(iit, eos, [](unsigned char ch) { 
          std::cout &lt;&lt; std::hex &lt;&lt; (int)ch &lt;&lt; ' ';  
      });
  
      std::cout &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>If I call my program like this:</p>
  
  <pre><code>myprog &lt;binfile.bin
  </code></pre>
  
  <p>The output I get is:</p>
  
  <pre><code>cout with array
  a1 58 2 1 3 2 1 15 30 50 55 4 2 0 0 0 a7 48 a0 46 a4 44 a7 42 4 40 8a 0 35 2c 77
   58 83 e9 78 9f 4f 34 6 e1 b2 57 3a c ef 18 54 54 1a 4d bf 2d 2 36 18 cb 4a c3 5
  8 20 fc 92 de bc 85 94 90 27 36 5 ea e5 ea e6 b 73 ef d1 9e 85 38 57 1e f6 62 9b
   8f 74 a3 0
  
  cout with stdin - redirecting file of same bytes as above
  a1 58 2 1 3 2 1 15 30 50 55 4 2 0 0 0 a7 48 a0 46 a4 44 a7 42 4 40 8a 0 35 2c 77
   58 83 e9 78 9f 4f 34 6 e1 b2 57 3a ef 18 54 54
  </code></pre>
  
  <p>Why does input reading stop at the 0xA1 character?  How do I get code to read complete binary file?</p>