title: C++, read and write to a binary file at the same time
body: <p>I wanted to know if it's possible to read a byte from a binary file with "fstream" and then change that byte and write it back.
  I tried this code but it didn't work and nothing happens but I'm sure it reads correctly.</p>
  
  <pre><code>file.open(path, ios::in|ios::out|ios::binary|ios::ate);
  file.seekg(0, ios::end);
  int size=file.tellg();
  file.seekg(0,ios::beg);
  char buffer;    
  for(int i=0;i&lt;size;i++)
  {
      file.read((char*)&amp;buffer,sizeof(char));
      buffer=(buffer+7)%256;
      file.write((char*)&amp;buffer, sizeof(char));
  }
  </code></pre>
  
  <p>should I take the file pointer one byte back after reading like this:</p>
  
  <pre><code>file.seekg(-1, ios::cur);
  </code></pre>
  
  <p>Thanks in advance.</p>