Hello, I just joined the C++ community to get help and help others if I can.
I currently have an assignment where I need to read 4 things from a file.
1.Bank account as a string
2.name as string
3.check balance as float
4.savings balance as float
We are using structures where all variables are stored for each account.
here's my fucntion where I read from the file
int loadCostumers(account accounts[])
{
int numCostumers = 0;
ifstream infileAccounts;
int count = 0;
//open file
infileAccounts.open("customer.dat");
//check if file opened
if (!infileAccounts)
{
cout << "File containing accounts not found" << endl;
cout << "Please close program and make sure file exists" << endl;
}
else
{
getline(infileAccounts, accounts[count].accountNumber, '#');
getline(infileAccounts, accounts[count].name, '#');
//read from file
}
return numCostumers;
}
the getline function works for the first two strings but I don't know how to read the next 2 numbers as they are not strings, I've tried the ignore() function but it doesnt work either. I need to know how I can read an integer or a float up to a certain character in this case a # sign.
here's how the text file looks: