WAP TO WRITE 10 RECORDS OF STUDENT IN BINARY FILE
#include<fstream.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<stdio.h>
struct student
{
char name[20];
int id;
int rollno;
};
void main()
{
clrscr();
student s1[10];
ofstream fout;
fout.open("abc.txt",ios::noreplace,ios::binary);
for(int i=0;i<10;i++)
{
cout<<"Enter the name:";
gets(s1[i].name);
cout<<"Enter id:";
cin>>s1[i].id;
cout<<"Enter roll no:";
cin>>s1[i].rollno;
fout.write((char*)&s1[i],sizeof(s1[i]));
}
fout.close();
}
#include<conio.h>
#include<process.h>
#include<string.h>
#include<stdio.h>
struct student
{
char name[20];
int id;
int rollno;
};
void main()
{
clrscr();
student s1[10];
ofstream fout;
fout.open("abc.txt",ios::noreplace,ios::binary);
for(int i=0;i<10;i++)
{
cout<<"Enter the name:";
gets(s1[i].name);
cout<<"Enter id:";
cin>>s1[i].id;
cout<<"Enter roll no:";
cin>>s1[i].rollno;
fout.write((char*)&s1[i],sizeof(s1[i]));
}
fout.close();
}
Comments
Post a Comment