Работаю с бинарным файлом напрямую, некорректно работает

Некорректно работает в месте чтения файла для смены зарплаты (40 строка). В консоль не выводитьcя сообщение "Enter new salary". Чат гпт не помогает :)

вот что выводит консоль

бинарный файл

Сам код:

#include <iostream>
#include <fstream>
using namespace std;

struct Employee{
   string surname, post;
   int age;
   double salary;
};

void input(Employee arr[], int amount);
void fwrit(Employee arr[], int amount);

int main(){

int n, num;
cout<<"Enter the number of employees: ";
cin>>n;

Employee emps[10];
cout<<"Enter employees"<<endl;
input(emps, n);
cout<<"Saving data to file..."<<endl;
fwrit(emps, n);

cout<<"if you want to change the employee's salary enter 1: ";
cin>>num;

if(num==1){
    fstream file("file.txt", ios::in | ios::out | ios::binary);
    if(!file.is_open()){
        cout<<"File is`t open!!! Error!!"<<endl;
        exit(1);
    }
    string name;
    cout<<"\tEnter surname: ";
    cin>>name;
    
    Employee emp;
    bool found = false;
    while(file.read((char*)&emp, sizeof(Employee))){
        if(emp.surname==name){
            cout<<"Enter new salary: ";
            cin>>emp.salary;
            found = true;
            file.seekg(-sizeof(Employee), ios::cur);
            file.write((char*)&emp, sizeof(Employee));
            cout<<"Data saved\n";
            break;
        }
    }
    if(!found){
        cout<<"Surname not found!!!"<<endl;
    }
    file.close();
}

return 0;

}


Ответы (0 шт):