Assuming the file “employee.dat” is already existing in binary format.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
class employee {
har name[20];
char address[20];
int age;
public:
void showdata()
{
cout<<"\nEmployee Name : ";
puts(name);
cout<<"\nEmployee Address : ";
puts( address);
}
int retage()
{
return age;
}
};
void search () {
employee emp;
ifstream ifs;
ifs.open("employee.dat",ios::binary);
while(ifs.read((char*)&emp,sizeof(emp)))
{
if(emp.retage()>30)
emp.showdata();
}
ifs.close();
}
void main()
{
clrscr();
search();
getch();
}