Monday, March 22, 2010

Binary files with the read and write() operations in c++

// binary files with the read and write() operations
#include
#include
#include
char filename[15]="BINARY";

void main()
{
clrscr();
float height[4]={175.5,153.0,167.25,160.70};
ofstream outfile(filename);// create output file stream object
outfile.write((char *)&height,sizeof(height)); // write to the file
outfile.close();//disconnect from binary file

ifstream infile(filename);//create input filestream object
infile.read((char *)&height,sizeof(height));//read from file

for(int i=0;i<4;i++)
{
cout.setf(ios::showpoint);//set format from one to another
cout<<<
// setprecision for floating point after decimal
}
infile.close();
}