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;
}
No comments:
Post a Comment