title: Binary Files in C++, changing the content of raw data on an audio file
body: <p>I have never worked with binary files before. I opened an <code>.mp3</code> file using the mode <code>ios::binary</code>, read data from it, assigned <code>0</code> to each byte read and then rewrote them to another file opened in <code>ios::binary</code> mode. I opened the output file on a media player, it sounds corrupted but I can still hear the song. I want to know what happened physically.</p>
  
  <p>How can I access/modify the raw data ( bytes ) of an audio ( video, images, ... ) using C++ ( to practice file encryption/decryption later )?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;fstream&gt;
      #include &lt;cstring&gt;
  
      using namespace std;
  
      int main(){
          char buffer[256];
          ifstream inFile;
          inFile.open("Backstreet Boys - Incomplete.mp3",ios::binary);
          ofstream outFile;
          outFile.open("Output.mp3",ios::binary);
          while(!inFile.eof()){
              inFile.read(buffer,256);
              for(int i = 0; i&lt;strlen(buffer); i++){
                  buffer[i] = 0;
              }
              outFile.write(buffer,256);
          }
          inFile.close();
          outFile.close();
      }
  </code></pre>