First question is what does the input file actually look like? What you have posted tells me what you need to read, but not what it is actually reading.
Line 9 creates a file stream variable "inFile", but how do you know that the file is open. Just because you tell it to open a file does not mean that it is.
Lines 13 - 17 are a little confusing as to why you did that.
Without the proper input file and the rest of the code it is hard to say what is wrong with out being able to test it.
The layout of the file is what I wrote, the file looks like this:
Handy Andy
12345
12345-1
Transaction account
5000
200
12345-2
Savings account
250
2
12345-3
Long Savings account
0
0
Lines 13-17 are working, that is just data members being set by the first two lines read from the file, and the file does read. But when I use it like this I only get Transaction accounts when loading the file, and only the first account number (12345-1 in the example above) but all three accounts are created. The other two gets no account number at all. So probably I'm not reading the file correctly, but I don't know what's wrong.
What I want it to do is read "Handy Andy" and set it as name (which it does), then read 12345 and set it as customer id (which it does).
But then I want it to read the account type below and add balance and credit/number of withdrawals and create a unique_ptr from the correct derived class that gets pushed to a vector of the base class.
So it took you 50 lines of code to find out you got into trouble.
That is a bad situation to get into.
So what you need to do is put your 50 lines to one side and learn how to simply read a file and print out what you have read. Nothing more complicated than that!!
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main () {
string Name;
int ID;
// blah, blah
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while ( myfile >> Name >> ID .... )
{
cout << Name << ' ' << ID ... << '\n';
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}