In the following code I would like to write the information to a disk. However I have been unable to figure this out. What do I need to include to make this possible? I have it successfully creating the new file, but it is not adding the correct information. Any tips are greatly appreciated.
Code:#include<fstream.h> #include<conio.h> #include<string.h> class Book { private: char title[30]; char name[30]; double price; int pages; public: void setBook(char t[], char n[], double pr, int pa); void displayBook(); }; void Book::setBook(char t[], char n[], double pr, int pa) { strcpy(title, t); strcpy(name, n); price = pr; pages = pa; }; void Book::displayBook() { cout<<title<<" was written by "<<name<<"."<<endl; cout<<"Price: $ "<<price<<". Total pages: "<<pages<<endl; cout<<""<<endl; }; void main() { Book books[10]; ofstream out("a:Book.txt"); if (out.fail()) cout<<"File was not opened."; else books[0].setBook("Legacy", "John Doe", 24.95, 185); books[1].setBook("Disturbed", "Jane Doe", 14.95, 75); books[2].setBook("How To Love", "Mark Davis", 39.95, 250); books[3].setBook("Crafts for Kids", "Jessica King", 19.95, 50); books[4].setBook("Angry Faces", "Melissa Hill", 9.95, 30); books[5].setBook("World Explorer", "Billy Joel", 59.95, 375); books[6].setBook("Scared Of The Dark", "B.J. Heckener", 29.95, 150); books[7].setBook("Men That Can't Love", "Helen Pat", 34.95, 200); books[8].setBook("Pitbulls", "Jack Frost", 14.95, 75); books[9].setBook("Crazy", "Little Jack", 19.95, 125); for ( int i = 0; i < 10; i++) books[i].displayBook(); out<<books; getch(); };



LinkBack URL
About LinkBacks


