I encountered an error while reading the file. It appears an error
Unhandled exception at 0x000FD618 in DeMo_QLNV.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000003)
in the paragraph. Exactly the line
ds[i] = x;
Around here:
while (!filein.eof())
{
x->Doc_File(filein);
ds[i] = x;
i++;
}
n = i;
I tried to change some code but still got an error. You help me fix this. I use Visual Studio 2017.
#include"iostream"
#include"fstream"
#include"string"
using namespace std;
class NhanVien
{
protected:
string maNhanVien;
string tenNhanVien;
string diaChi;
float luongCoBan;
float heSoLuong;
public:
virtual void Doc_File(ifstream &);
virtual void Xuat_Thong_Tin();
};
//Install the doc file in the parent folder
void NhanVien::Doc_File(ifstream &filein)
{
getline(filein, maNhanVien, ',');
filein.seekg(1, 1);
getline(filein, tenNhanVien, ',');
filein.seekg(1, 1);
getline(filein, diaChi, ',');
filein >> heSoLuong;
filein.seekg(1, 1);
filein >> luongCoBan;
filein.seekg(1, 1);
}
//information
void NhanVien::Xuat_Thong_Tin()
{
cout << "\nMa Nhan Vien: " << maNhanVien;
cout << "\nHo Ten Nhan Vien: " << tenNhanVien;
cout << "\nDia Chi Nhan Vien: " << diaChi;
cout << "\nHe So Luong: " << heSoLuong;
cout << "\nLuong Can Ban: " << (size_t)luongCoBan;
}
//Menu
void Menu(NhanVien *ds[], int &n)
{
ifstream filein; int i = 0;
filein.open("NHANVIEN.txt", ios_base::in);
while (true)
{
system("cls");
cout << "\n\n\t\t ===== MENU =====";
cout << "\n1. Doc Thong Tin Nhan Vien Tu File.";
cout << "\n2. Xuat Thong Tin Nhan Vien.";
cout << "\n0. Thoat.";
cout << "\n\n\t\t ===== END =====";
int luachon;
cout << "\nNhap lua chon: ";
cin >> luachon;
if (luachon == 1)
{
///////////////////////////////////////
The bottom part I encountered an error.
///////////////////////////////////////
NhanVien *x = new NhanVien;
while (!filein.eof())
{
x->Doc_File(filein);
ds[i] = x;
i++;
}
n = i;
//////////////////////
//Below is no problem.
//////////////////////
}
else if (luachon == 2)
{
for (int i = 0; i < n; i++)
{
cout << "\n\n\t\tNHAN VIEN THU " << i + 1 << endl;
ds[i]->Xuat_Thong_Tin();
}
system("pause");
}
else break;
}
filein.close();
}
int main()
{
NhanVien *ds[100];
int n = 0;
Menu(ds, n);
system("pause");
return 0;
}
User contributions licensed under CC BY-SA 3.0