Mọi người xem giúp e với ạ, bị lỗi gì mà e chạy ctrinh cứ hiện: Exception thrown at 0x755E79D2 in BTOT.exe: Microsoft C++ exception: std::bad_array_new_length at memory location 0x008FF710.
If there is a handler for this exception, the program may be safely continued.
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
struct SinhVien
{
string MSSV;
string ho;
string ten;
//double diem[so_mon];
int diem1;
int diem2;
};
void docFile(SinhVien * &arr, int &n);
void inDanhsach(SinhVien *arr, int n);
void timSinhVien(SinhVien *arr, int n, string MSSV);
int main()
{
SinhVien*arr = NULL;
int n;
docFile(arr, n);
inDanhsach(arr, n);
string MSSV;
cout << "Nhap MASV can tim: ";
getline(cin, MSSV);
timSinhVien(arr, n, MSSV);
delete[]arr;
system("pause");
return 0;
}
void docFile(SinhVien * &arr, int &n)
{
ifstream in;
in.open("sinhvien.txt");
if (in.is_open())
{
// cin.ignore();
arr = new SinhVien[n];
for (int i = 0; i < n; i++)
{
getline(in, arr[i].MSSV, '-');
getline(in, arr[i].ho, '-');
getline(in, arr[i].ten, '-');
cin>>arr[i].diem1;
cin>> arr[i].diem2;
in.ignore();
}
in.close();
}
}
void inDanhsach(SinhVien *arr, int n)
{
for (int i = 0; i < n; i++)
{
cout << arr[i].MSSV << "-" << arr[i].ho << "-" << arr[i].ten <<"-"<<arr[i].diem1<<"-"<<arr[i].diem2<< endl;
}
}
void timSinhVien(SinhVien *arr, int n, string MSSV)
{
for (int i = 0; i < n; i++)
{
if (MSSV == arr[i].MSSV)
{
cout << arr[i].MSSV << "-" << arr[i].ho << "-" << arr[i].ten << "-" << arr[i].diem1 << "-" << arr[i].diem2 << "-" << (arr[i].diem1 + arr[i].diem2) / 2 << endl;
return;
}
}
cout << "Khong tim thay!\n";
}