#include <vector>
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
class Bad{};
template<class T>
char* as_bytes(T&i){
void* addr = &i;
returnstatic_cast<char*>(addr);
}
int main()
{
//input file name
cout << "Please enter input file name\n ";
string iname;
cin >> iname;
ifstream ifs(iname, ios_base::binary);
if (!ifs) throw Bad{};
//output file name
cout << " Please enter output file name\n";
string oname;
cin >> oname;
ofstream ofs(oname, ios_base::binary);
if (!ofs) throw Bad{};
//reading
vector<int> v;
for (int x; ifs.read(as_bytes(x), sizeof(int));)
v.push_back(x);
for (int x : v) cout << x << endl; // looking at number i got
//my own improvement of the code
//writing what read to other file
for (int x : v)
ofs.write(as_bytes(x), sizeof(int)); // note : writing bytes
ofs.close(); // this i added also because without closing the file i got
//an empty file after program finished running
system("pause");
return 0;
}