C++ Program to Read and Write a Binary File

#include<iostream.h>
#include<conio.h>
#include<fstream>
const char* filename="BINARY";
int main()
{
float height[4]={ 150.5, 160.6, 180.5, 190.5};
ofstream outfile;
outfile.open(filename);
outfile.write((char *) & height, sizeof(height)); // write to file outfile
outfile.close();
for(int i=0;i<4;i++)
height[i]=0;
ifstream infile;
infile.open(filename);
infile.read((char*) & height, sizeof(height)); // read from file infile
for(i=0;i<4;i++)
{
cout.setf(ios::showpoint);
cout<<setw(10)<<setprecision(2)<<height[i];
}
infile.close();
return 0;
}