文件处理C++

File handling C++

本文关键字:C++ 处理 文件      更新时间:2023-10-16

我正在创建iventory管理系统,但实际情况是我输入的数据没有进入文件,也没有编译。我想知道是什么我的代码完全错误。

我之所以增加缺席日期是为了从基本工资中扣除。提前谢谢。这是我的程序

void input()
{ 
    ofstream empfile;
   empfile.open("emp.txt",ios :: app);
   cout << "Enter the National Identity Card Number of the Employer n";
   cin >>nic;
   cout << "Enter the first name of the Employer n";
   cin >>firstName;
   cout <<"Enter the last name of the Employer n";
   cin >>lastName;
   cout << "Enter the date of birth [date/month/year] n";
   cin >> dob;
   cout <<"Enter your Telephone Number n";
   cin>> pnum;
   cout <<"Enter your address n";
   cin >> address;
   cout <<"Your daily basic Salary is Rs20000 n";
   cout << "How many days did she/he haven't reported to the Factory? n";
   cin >>days;
    if(days=1)
    {
      salary=salary-1000;
    }
    else if(days<3 && days>1)
    {
        salary=salary+2000;
    }
    else if(days>=3)
    {
       salary=salary-3000;
    }
    else
    {
        cout << "Please enter a valid number of days n";
    }
   empfile >> nic >> ' ' >>firstName >> ' ' >> lastName >> ' ' >> dob >> ' ' >>pnum>> ' ' >>address >> ' ' >> salary>> endl;
   empfile.close();

}

您只需将箭头转到另一侧,这就是为什么数据不会转到empfile对象

 empfile << nic << ' ' <<firstName << ' '<< lastName << ' '<< dob << ' '<<pnum<<' '<<address <<' '<<salary<< endl;
   empfile.close();