Reading into a class

Hi,

I'm working on a library reference program and currently trying to read from a file that has a mix of tabs and whitespaces. There are six values per line, and I need to stop at tabs but not whitespaces (because some of the values are multiple words) as in:

C8394 Kundera Milan The Unbearable Lightness of Being novel available
C1934 Heidegger Martin Being and Time philosophy unavailable

So there are tabs in between values, but whitespaces in between book titles.

So I did this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "library.h"

using namespace std;
#define MAXBOOKS 10000

int main()
{
        library booklist[MAXBOOKS];
        ifstream fin;
        string filename;
        int length = 0;
        string names;
        string array[7];

        cout << "Enter the name of the file: ";
        cin  >> filename;
        fin.open(filename.c_str());

        if ( fin.fail() ) {
        cerr << "Could not open file " << filename << " for reading.\n";
        exit(1);
        }


        while ( length < MAXBOOKS && !fin.eof() )
        {
                for(int i = 0; i <= 6; i++)
                {
                        getline(fin, names, '\t');
                        array[i] = names + ' ';
                }

                for (int j = 0; j <= 6; j++)
                {
                        cout << array[j];
                }
                length++;
        }


          fin.close();


}


I merely have the cout to check that it's working. Where I'm stuck is how to I send it to the class array, or is there an easier way to send the values to the class all at once?

The class has the values ISBN, lastname, firstname,title,genre,availibility, so I know I have to call a function to send those values there but I don't get how to keep doing it for each line.

Thanks for any help you can give.
Last edited on
Topic archived. No new replies allowed.