Please improve my code:

I was trying to creat a code which reads input from file. The names were separated by "_" (underscore). The function reads the first string in the file, which is the total number of names in the file, which will be used in the for loop.

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
void loadFromFile(list<NamePtr>& nameList)
{
    string name;
    ifstream infile("C:\\lib.txt");
    infile >> name;

    StringList list;
    int size;
    double cbal;
    int cday;
    int cyr;
    string sCount;
    int nCount;

    list = Split(name, "_");
    size = list.size();

    if (size > 0) // the first strings is the number of names which will be used for the 'for loop'
        sCount = list[0];
        nCount = StringToNumber(sCount);

    int y = 1;

    for(int q = 0; q < nCount; q++)
    {
        if (size > y)
        {
            cout << y << endl;
            first = list[y];
            y++;
        }
        if (size > y)
        {
            middle = list[y];
            y++;
        }
        if (size > y)
        {
            last = list[y];
            y++;
        }
        if (size > y)
        {
            suf = list[y];
            y++;
        }
        if (size > y)
        {
            bal = list[y];
            cbal = StringToNumber(bal);
            y++;
        }
        if (size > y)
        {
            mo = list[y];
            y++;
        }
        if (size > y)
        {
            day = list[y];
            cday = StringToNumber(day);
            y++;
        }
        if (size > y)
        {
            yr = list[y];
            cyr = StringToNumber(yr);
            cout << yr << endl;
            y++;
        }

        Account* pA = new Account(first, middle, last, suf, cbal, mo, cday, cyr);

        accList.push_back(pA);
    }
    infile.close();
}


This is what's in the file:

3_jack_ryan_recruit_jr._20_january_2_2000_stephen_hawking_ _20_january_2_2000_william_henry_gates_III_30_february_3_2000_
Topic archived. No new replies allowed.