When i am running this program having eroor in reading file please help me out
#include<iostream>
#include<conio.h>
#include<string>
#include<fstream>
using namespace std;
class employee
{ private:
}
void reterive()
{ ifstream in;
in.open("eb",ios::in | ios::binary);
if(!in)
cout<<"cannot reterive..";
else
{ employee *temp=NULL;
employee e(0);
while(1)
{ in.read((char*) &e,sizeof(employee));
employee *p=new employee(e); //dynamically creating an employee that will have the same value as 'e' and saving its address in p. Every node in link list has different location so p will be different. &e is always same. So actually read node from file in e than create a node dynamically with same contents and address will be save in p.
if(list==NULL)
{list=p;
temp=list;
p->show();}
else{
temp->next=p;
temp=temp->next;
e.show();
if(e.next==NULL)
{ e.setcount(e.getid()); break;}
}
}
in.close();
}
}
};
void main()
{
db obj;
try{ obj.reterive();
int op;
while(1)
{ cout<<endl<<"Enter 1 to hire ,2 for remove ,3 for displayall, 4 for search by name.. 5 for exit";
cin>>op;
switch(op)
{case 1:
obj.hire(); break;
case 2:
obj.remove(); break;
case 3:
obj.displayall(); break;
case 4:
obj.searchbyname(); break;
}
if(op==5)
break;
}
obj.save();
}
catch(...)
{cout<<"error..";}
getch();
}
The simplest alternative is to open the file in text mode instead of binary mode.
Then output each member variable id and name as ordinary text, using suitable delimiters. For example, use '\t' to separate each variable and '\n' to mark the end of each record.
Well, I'm not sure it was that important, maybe this is distracting from the real issue which is this: are you now able to go ahead and modify the program so that it works as required, or not? If not, where are you stuck.