Một phần bài lớn của mình đây bạn:
ĐÂY LÀ PHẦN ĐỌC:
void DocFile(vector<NhanVien*> &DanhSach)
{
int k = 1;
DanhSach.clear();
ifstream fin("DanhSach.txt");
while (!fin.eof())
{
bool Loai;
string name;
int year;
float luongCB, HSLuong, NoXacDinh;
//-------------
fin >> Loai;//Toan tu nhap bo qua cac ki tu khoang trang
fin.get();
getline(fin, name, '#');
fin >> year;
fin.get();//bo #
//0#Nguyen Dai Duong#9#9#9
fin >> luongCB;
fin.get();//bo #
fin >> HSLuong;
fin.get();//bo #
fin >> NoXacDinh;
char ch;
ch = fin.get();
if ( ch == '\n')
{
if (!Loai)
{
CongNhan *temp = new CongNhan;
temp->NhapDL(name, year, luongCB, HSLuong, NoXacDinh);
DanhSach.push_back(temp);
}
else
{
QuanLy *temp = new QuanLy;
temp->NhapDL(name, year, luongCB, HSLuong, NoXacDinh);
DanhSach.push_back(temp);
}
}
//cout << k++ << fin.eof() << ch;//test
}
}
ĐÂY LÀ PHẦN GHI:
void GhiFile(CongNhan *temp)
{
ofstream fout("DanhSach.txt",ios::app);
fout << temp->PhanLoai()<<"#";
fout << temp->GetHoTen() << "#";
fout << temp->GetNamSinh() << "#";
fout << temp->GetLuongCoBan() << "#";
fout << temp->GetHeSoLuong() << "#";
fout << temp->GetSoNgayLam() << "\n";
}
void GhiFile(QuanLy *temp)
{
ofstream fout("DanhSach.txt", ios::app);
fout << temp->PhanLoai() << "#";
fout << temp->GetHoTen() << "#";
fout << temp->GetNamSinh() << "#";
fout << temp->GetLuongCoBan() << "#";
fout << temp->GetHeSoLuong() << "#";
fout << temp->GetPhuCap() << "\n";
}
Khi đọc khó hiểu, mong bạn thông cảm