organisation.txt
이라는 텍스트 파일에서 직원 번호 (클래스를 선언하지 않고), 이름, 직업 및 직원을 표시하고 싶습니다. 변수는 OrganisationRecord
클래스에 선언되었습니다.파일에서 데이터 읽기 및 변수에 저장
어떻게 텍스트 파일의 데이터를 가져 와서 해당 변수에 저장할 수 있습니까?
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#define ORGANISATIONALRECORDSFILE "organisation.txt"
#define HRRECORDSFILE "HR_records.txt"
#define PAYROLLRECORDSFILE "payroll_records.txt"
using namespace std;
class OrganisationRecord
{
private:
public:
string name;
string occupation;
string department;
};
class HRRecord
{
private:
public:
string address;
string phonenumber;
string ninumber;
};
class PayrollRecord
{
private:
public:
string ninumber;
double salary;
};
class PayrollProcessing
{
private:
ifstream inputfile;
ofstream outputfile;
vector<OrganisationRecord> OrganisationRecords;
vector<HRRecord> HRRecords;
vector<PayrollRecord> PayrollRecords;
public:
void loadOrganisationRecords(string filename);
void loadHRRecords(string filename);
void loadPayrollRecords(string filename);
void displayEmployeeOfSalaryGTE(double salary);
//GTE = greater than or equal to
};
void PayrollProcessing::loadOrganisationRecords(string filename)
{
inputfile.open(ORGANISATIONALRECORDSFILE);
if (!inputfile)
{
cout << "the organisation records file does not exist" << endl;
return;
}
OrganisationRecord _organisationrecord;
int employeenumber;
while (inputfile >> employeenumber)
{
while (inputfile >> _organisationrecord.name)
{
cout << _organisationrecord.name;
cout << _organisationrecord.occupation;
cout << _organisationrecord.department <<endl;
}
OrganisationRecords.push_back(_organisationrecord);
}
}
int main(void)
{
PayrollProcessing database1;
database1.loadOrganisationRecords(ORGANISATIONALRECORDSFILE);
return 0;
}
organisation.txt 여기
0001
Stephen Jones
Sales Clerk
Sales
0002
John Smith
Programmer
OS Development
0003
Fred Blogs
Project Manager
Outsourcing
는'?'나는 당신이 오류가 나는의 명백한 문제 외에도 질문 – UKMonkey
는 "왜 당신이 원하는 것이 정확히 어떤 상태로 질문을 바꿔 필요가 있다고 생각 "그 다음 질문은"수업에서 선언하지 않고 정확히 무엇을 의미합니까? " 그 유형의 레코드에 대한 유효한 데이터 조각이라면 실제로 그 속성/필드가 설정되어 있어야합니다 ... 또한 명명 규칙, 클래스의 이름 지정 방법 등을 다시 생각해 볼 수도 있습니다. 당신은 회사를 설명하고 있지만 분야에 따라 사실 직원 정보가 나와 있습니다 –
을 편집 한 확인 – Taegost