读取文件时遇到错误。出现错误
在该段中的DeMo_QLNV.exe中0x000FD618处未处理的异常:0xC00001A5:检测到无效的异常处理程序例程(参数:0x00000003)
。正是这一行
ds[i] = x;
在这里:
while (!filein.eof())
{
x->Doc_File(filein);
ds[i] = x;
i++;
}
n = i;
我试图更改一些代码,但仍然出现错误。你帮我解决这个问题。我使用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;
}