====== C - C++ Files - Class to a file ====== #include #include using namespace std; class item { private: int itno,stock; char itname[10]; float pprice,sprice; public: void getitem() { cout<<"Enter the item no:"; cin>>itno; cout<<"Enter the item name:"; cin>>itname; cout<<"Enter the purchase price:"; cin>>pprice; cout<<"Enter the selling price:"; cin>>sprice; cout<<"Enter current stock:"; cin>>stock; } }; int main() { fstream f; item i; char wish; f.open("item.dat",ios::app); do { i.getitem(); f.write((char *)&i,(sizeof(i))); cout<<"Wish to add another item(y/n):"; cin>>wish; } while(wish=='y'); f.close(); return 0; }