...
...
string urlFile_quanglong = "./API.txt";
//Main.../
//Read file///
bool docDanhSachNhanVienTuFile(NhanVien *dsnv, int &n, string &urlFile, int maxNhanVien)
{
ifstream fileNhap(urlFile);
if (!fileNhap)
{
return false; // Không mở được file
}
string dong;
while (getline(fileNhap, dong) && n < maxNhanVien)
{
stringstream ss(dong);
getline(ss, dsnv[n].ma_nhan_vien, ','); // Đọc mã nhân viên
getline(ss, dsnv[n].ho_ten, ','); // Đọc họ tên
string ngay_sinh, thang_sinh, nam_sinh;
getline(ss, ngay_sinh, '/'); // Đọc ngày sinh
getline(ss, thang_sinh, '/'); // Đọc tháng sinh
getline(ss, nam_sinh, ','); // Đọc năm sinh
dsnv[n].ngay_sinh = stoi(ngay_sinh);
dsnv[n].thang_sinh = stoi(thang_sinh);
dsnv[n].nam_sinh = stoi(nam_sinh);
getline(ss, dsnv[n].chuc_vu, ','); // Đọc chức vụ
getline(ss, dsnv[n].phong_ban, ','); // Đọc phòng ban
string luong;
getline(ss, luong); // Đọc lương
dsnv[n].luong = stod(luong);
n++;
}
return true;
}
//Read file///
I’m having a problem: I can’t read the file.
However, when I use the old API.txt file, it can run again, but cannot access data. When I change to another file, I get the error
Abort trap: 6
New contributor
user25416403 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.