Need a project done?

C++ Programming Developer

Search This Blog

Write files in binary C++


Write files in binary in C++.

#include <iostream>
#include <fstream>
using namespace std;

int main(){
int a[10];
for (int i = 0; i<10; i++){
a[i] = i;
}

ofstream os("REHAN.txt", ios::binary);
os.write(reinterpret_cast<char*>(a),10*sizeof(int));

os.close();
for (i = 0; i<10; i++){
a[i] = 0;
}

ifstream is("REHAN.txt",ios::binary);
is.read(reinterpret_cast<char*>(a),10*sizeof(int));
for (i = 0; i<10; i++){
cout << a[i] ;
}
return 0;
}
"Don't let anyone ever make you feel like you don't deserve what you want."