#include #include using namespace std; void main() { int N; int data[2]; int read[3]; ofstream fout; ifstream finp; cout<<"This is a simple program that illustrates how to use binary input output\n\n"; cout<<"Please enter three integer numbers: "; cin>>N>>data[0]>>data[1]; cout<<"I', about to open a binary file 'bin_fio.bin' "; fout.open("bin_fio.bin", ios_base::out | ios_base::binary); if( fout.fail() ){ cerr<<"Error: cannot open file 'bin_fio.bin' for writing\n"; return; } cout<<"[OK]\n"; cout<<"Writing information into the file:\n"; cout<<" - first a number: "; fout.write(reinterpret_cast(&N), sizeof(int)); cout<(data), sizeof(int)*2); cout<<2*sizeof(int)<<" bytes written\n"; cout<<"Closing the file "; fout.close(); cout<<"[OK]\n"; cout<<"\nNow, I'm about to read it all back. \nSo, I'm opening the same file for reading "; finp.open("bin_fio.bin", ios_base::in | ios_base::binary); if( finp.fail() ){ cerr<<"Error: cannot open file 'bin_fio.bin' for reading\n"; return; } cout<<"[OK]\n"; cout<<"Now, I'm reading the data as an array of three integers "; finp.read(reinterpret_cast(read), sizeof(int)*3); cout<<3*sizeof(int)<<" bytes read\n"; cout<<"The numbers read are:"; for(int i=0;i<3;i++) cout<<" "<