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.
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();
}