Hello guyz!!! Please help me to search a records in text file.
The text file written of this records:
Ben 2010-0001 300.00
John 2010-0003 400.00
Mike 2010-0002 190.00
I want to input only the employee id and it will display the name and salary if that record is existed.
Here's my code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
string Ename;
int emp_rec, no, emp;
string cname,
int emprec, no_na;
ifstream EmpRec;
ofstream DTR;
EmpRec.open("employee.txt");
if (!EmpRec)
{
cout<<"Cannot open input file"<<endl;
cout<<"Program Terminated"<<endl;
return 1;
}
EmpRec>>Ename>>emp_rec>>no;
while(EmpRec)
{
cout<<"Enter Employee record: ";
cin >>emp;
if (emp_rec==emp){
cname=Ename;
emprec=emp_rec;
no_na=no;
}
}
cout<<cname<<endl;
cout<<emprec<<endl;
cout<<no_na;
return 0;
}
Tnx : )