title: Converting text file to binary, and back to text
body: <p>I am trying to convert a text file to binary, then read in that binary file and convert it back to text. This is the code I wrote for it,but the intermediate file, i.e. the binary file,<code>"ex7_out1"</code>, is also in text,I was expecting binary encoded form of the text, how does this happen?</p>
  
  <pre><code>#include "std_lib_facilities.h"
  
  int main()
  {
      //to binary from text
      ifstream ifs{"ex7_in", ios_base::binary};
      ofstream ofs{"ex7_out1", ios_base::binary};
      char ch;
      while(ifs.get(ch)) { ofs.write(as_bytes(ch),sizeof(char)); }
  
      ifs.close();
      ofs.close();
  
      //from binary to text
      ifstream ifs1{"ex7_out1", ios_base::binary};
      ofstream ofs1{"ex7_out2"};
      char ch1;
      while(ifs1.read(as_bytes(ch1), sizeof(char))) { ofs1 &lt;&lt; ch1; }
  
  }
  </code></pre>
  
  <p>The input file <code>"ex7_in"</code> contains one line of text.
  This is an excercise from Bjarne Stroustrup's book,Programming:Principles and Practice Using C++.</p>