i want to save book data to a file. Wrote code given below. Code below is working fine on my personal system, but it is overwriting previous file data on some other systems.
class Book
{
private:
int id, price;
public:
void inp()
{
cin >> id >> price;
}
void disp()
{
cout << "id = " << id << "\nPrice = " << price << endl;
}
};
void Write()
{
ofstream of;
Book b;
b.inp();
of.open("b.dat",ios::binary | ios::app );
of.write((char*)&b, sizeof(Book));
of.close();
}
enter code here
Aucun commentaire:
Enregistrer un commentaire