I'm trying to read some data from a .txt file into some variables, which will then be passed into a class object. The first few values from the text file are working fine (firstNames, surname, dob, accountNo), however the bankNumbers are causing trouble. An account holder can have between 0 and 5 accounts, so some may have 3, or 0, or 5. At the minute, it reads in the next 5 values, so if my first user has only 3 accounts, my program will read in the accountNo and surname as the 4th and 5th values of the array. How do i make the program only read the number of numbers that are there? Here is an example text file:
548161 Bloggs Joe 01-01-1970 1567 1824 2041
378941 Smith John 25-12-1985 
123085 Claus Santa 30-05-1910 7829 2398 4890 1473 4392
318945 Obama Barack 14-02-1965 4382 3944
And here is my code:
int main()
{
    ifstream accountsFile;
    string surname, firstNames, dob;
    int accountNo, bankNumbers[5];
    accountsFile.open("Accounts.txt", ifstream::in);
    int i = 0;
    while (!accountsFile.eof())
    {
        accountsFile >> accountNo >> surname >> firstNames >> dob;
        for (int i = 0; i < 5; i++)
        {
            accountsFile >> bankNumbers[i];
        }
        accounts[i] = Account(accountNo, surname, firstNames,  dob, bankNumbers);
        i++;
    }
    accountsFile.close();
    system("pause");
    return 0;
}
 
     
    