class A {
string name;
size_t num;
unique_ptr<char[]> p;
public:
void write(ostream& os) {
os.write((char*)this, sizeof(a));
os.write((char*))p.get(), num);
}
There is a file made by write().
I open the file with ios::binary, and i try to get a lot of A with read().
void read(istream& is) {
is.read(reinterpret_cast<char*>(this), sizeof(A));
p = make_unique<char>(num);
is.read(p.get(), num)
}
I can’t get any data with read() and program return abort() error.
I’d appreciate it if you could help me.
New contributor
jade808 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.