// reading an entire binary file
#include <iostream>
#include <fstream>
#include <bitset>
#include<vector>
using namespace std;
int main () {
streampos size;
char * memblock;
char * memblock2;
bitset<8> bbb =8;
vector<int> vecint;
ifstream file ("3.rar", ios::in|ios::binary|ios::ate);
ofstream ofile("4.rar", ios::out|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg();
memblock = new char [size];
memblock2 = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
for (int j=0;j<size;j++)
{
bbb =memblock[j];
vecint.push_back(bbb.to_ulong());
}
for (int j=0;j<size;j++)
{
memblock2[j] = vecint[j];
}
ofile.write(memblock2, size);
file.close();
cout << "the entire file content is in memory";
delete[] memblock;
delete[] memblock2;
}
else cout << "Unable to open file";
return 0;
}