Sunday, August 23, 2009

WRITING NUMBERS IN TO FILE

#include"fstream.h"
#include"conio.h"
void main()
{
Clrscr();
float ht1[4],ht[4]={13,14,54,66};
fstream file;
file.open("aaa.a",ios::out);
file.write((char *) &ht,sizeof(ht));
file.close();
file.open("aaa.a",ios::in);
file.read((char *) &ht1,sizeof(ht1));
for(int i=0;i<4;i++)
{
printf("%f",ht1[i]);
printf("\n");
}
file.close();
getch();
}

OUTPUT:
The numbers in the floating point array ht are first converted into character type and then they are stored in the file with the file name “aaa.a” and then they are retrieved from the file with file name “aaa.a” and stored in the array of floating point ht1 and these values are printed as follows.

13
14
54
66

No comments:

Post a Comment