I know it's a lot of code but any help anyone can give would be amazing. Basically when I re-write out to the binary file it must not be working because when I try to print it it only prints the record I updated.
void updateRecord()
{
int key;
int gpos;
cout << "Enter the ID of the employee whose information you would like to update"<<endl;
cin >> key;
bool posnotfound;
long pos=0;
posnotfound = search (pos, binfile, key);
binfile.open ("data.dat", ios::in);
if (posnotfound == true)
cout << "RECORD NOT FOUND";
else
{
binfile.seekg(pos-sizeof(person), ios::beg);
binfile.read ((char*)&person,sizeof(person));
cout << person.ID<<endl;
cout << person.lname;
cout << person.fname<<endl;
cout << person.position<<endl;
cout << person.hours<<endl;
cout << person.salary<<endl;
int switcher;
cout << "What do you want to update?"<<endl;
cout << "1. Position"<<endl;
cout << "2. Hours"<<endl;
cout << "3. Salary"<<endl;
cin >> switcher;
switch (switcher)
{
case 1:
cout <<"Enter the employee's new position"<<endl;
cin >> person.position;
break;
case 2:
cout << "Enter the employee's new hours"<<endl;
cin >> person.hours;
break;
case 3:
cout << "Enter the employee's new salary"<<endl;
cin >> person.salary;
break;
}
cout << person.ID<<endl;
cout << person.lname;
cout << person.fname<<endl;
cout << person.position<<endl;
cout << person.hours<<endl;
cout << person.salary<<endl;
binfile.close();
binfile.open("data.dat",ios::out);
binfile.seekp(pos-sizeof(person),ios::beg);
binfile.write ((char*)&person,sizeof(person));
binfile.close();
binfile.open("data.dat",ios::in);
}
return;
}