a/c cho em hỏi, e chỉ làm vào ra file bình thường nhưng mà lúc chạy nhập xuất xong hết rồi nhưng đến cuối lại báo lỗi has stopped working là như thế nào ạ.
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class sinhvien{
private:
int maso;
string hoten;
public:
void nhap(){
cout<<"nhap ho ten: "; getline(cin,hoten);
cout<<"nhap ma so: "; cin>>maso; cin.ignore();
}
void xuat(){
cout<<"ho ten: "<<hoten<<endl;
cout<<"ma so: "<<maso<<endl;
}
void ghitep(){
fstream ghi("tepx.dat",ios::out|ios::binary);
ghi.write(reinterpret_cast <const char *>(this),sizeof(sinhvien));
ghi.close();
}
void doctep(){
fstream doc("tepx.dat",ios::in|ios::binary);
sinhvien a;
doc.read(reinterpret_cast <char *>(&a),sizeof(sinhvien));
a.xuat();
}
};
main(){
sinhvien x;
x.nhap();
x.ghitep();
cout<<"thong tin doc tu file: "<<endl;
x.doctep();
}