Ok here it is: I want to read a file backwards, the catch is that I want to do this in binary mode to make a, really lame, data encryption program. Is there any easy way (<10 lines) To do this?

You could read the file into an array, and copy it into a new array, and put the new data in backwards

I know this sounds stupid but would it be easier to write the file backwards instead of reading it backwards?

> would it be easier to write the file backwards instead of reading it backwards?

No.


If the file is small,

#include <iostream>
#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>

int main()
{
   std::ifstream file( __FILE__, std::ios_base::binary ) ;
   file >> std::noskipws ;

   typedef unsigned char byte ;
   std::istream_iterator<byte> bof(file), eof ;
   std::vector<byte> seq( bof, eof ) ;

   std::for_each( seq.rbegin(), seq.rend(), []( byte b ) { std::cout << b ; } ) ;
   std::cout << '\n' ;
}