Hello codeguru,

I'm working on a program using class booktype... to hold information about various books that I have saved on a txt file. Each object of the class book type holds the author, publisher, ISBN, number of copies in stock.



I am still very much new at c++ and not exactly sure how to get in info from the file I've made earlier..


Code:
#include<iostream>
#include<iomanip>
#include<string>
#include<cstring>
#include<fstream>
using namespace std;

class bookType
{
public:
    string title;
    string author;
    string publisher;
    int ISBN;
    string inStock;

int main()
{
    bookType listed;

    fstream books("books.txt", ios::out | ios::in | ios::binary);
    if(!books)
    {
                cout<<"Error opening data file.\n";
                return 0;
    }

          while(!books.eof())
    {
        cout<<listed.title<<endl;
        cout<<listed.author<<endl;
        cout<<listed.publisher<<endl;
        cout<<listed.ISBN<<endl;
        cout<<listed.inStock<<endl;
        books.read(reinterpret_cast<char *>(&listed),sizeof(listed));
    }books.close();
    return 0;
}
also the text file is formatted where after I've entered the author's name I then hit return, then publisher then I hit return, ISBN then return, and so forth does that effect the program?

as for my txt file this is what I have
Code:
Moby Dick
Sebastian Armesto
Oberoson Books Ltd
0001
201
The Scarlet Letter
Nathaniel Howthorne
eBookit.com
0002
65
Dracula
Bram Stroker
Archibald Constable and Company
0003
103
Lord of the files
William Golding
Faber and Faber
0004
65
To Kill a Mockingbird
Harper Lee
J.B. Lippincott & Co.
0005
26
as always your help is very much appreciated thanks..