#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<fstream.h>
struct stu
{
char name[20];
float per;
};
void main()
{
clrscr();
ofstream fout;
stu s1;
char ch;
fout.open("emp.dat",ios::out|ios::binary);
if(!fout)
{
cout<<"not found";
getch();
exit(1);
}
while(ch!='n')
{
cout<<"enter the name\n";
gets(s1.name);
cout<<"enter the percentage\n";
cin>>s1.per;
fout.write((char*)&s1,sizeof(s1));
cout<<"more record\n";
cin>>ch;
}
fout.close();
ifstream fin;
// stu s1;
// char ch;
fin.open("emp.dat",ios::in|ios::binary);
if(!fin)
{
cout<<"not found";
getch();
exit(1);
}
// fflush(stdin);
while(fin.read((char*)&s1,sizeof(s1)))
{
cout<<"name "<<s1.name<<"\n";
cout<<"percentage "<<s1.per<<"\n";
}
fin.close();
getch();
}
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<fstream.h>
struct stu
{
char name[20];
float per;
};
void main()
{
clrscr();
ofstream fout;
stu s1;
char ch;
fout.open("emp.dat",ios::out|ios::binary);
if(!fout)
{
cout<<"not found";
getch();
exit(1);
}
while(ch!='n')
{
cout<<"enter the name\n";
gets(s1.name);
cout<<"enter the percentage\n";
cin>>s1.per;
fout.write((char*)&s1,sizeof(s1));
cout<<"more record\n";
cin>>ch;
}
fout.close();
ifstream fin;
// stu s1;
// char ch;
fin.open("emp.dat",ios::in|ios::binary);
if(!fin)
{
cout<<"not found";
getch();
exit(1);
}
// fflush(stdin);
while(fin.read((char*)&s1,sizeof(s1)))
{
cout<<"name "<<s1.name<<"\n";
cout<<"percentage "<<s1.per<<"\n";
}
fin.close();
getch();
}
No comments:
Post a Comment