I need to read a file into a struct so i can print out a monthly bank statement after adding all deposits and with drawkls from another file but im having trouble reading the fileinto the array this is what i have so far..
#include <iostream> // Need for cout,cin
#include <iomanip> // Need setf,fixed,showpoint,setprecision
#include <fstream> // Needed for files
#include <cstdlib> // Needed for exit function
#include <string> // Need for string class
using namespace std;
struct PersonAcct // struct account holds customer info
{
int acct_num; // customer account number
string name; // customers name
double acct_bal; // customers account balance
};
int main ()
{
PersonAcct statement[20];
int counter;
ifstream accountsinFile;
ifstream transactioninFile;
// try to open the file
accountsinFile.open("accounts.txt",ios::in);
transactioninFile.open("transactions.txt",ios::in);
if(!accountsinFile.is_open())
{
cerr << "Account File open Error" ;
cout << " Press enter to continue" << endl;
cin.ignore();
char ch = cin.get();
return 0;
}
if (!transactioninFile.is_open())
{
cerr << "Transaction File open error " ;
cout << " Press enter to continue" << endl;
cin.ignore();
char ch = cin.get();
return 0;
}
for ( counter = 0; counter < 20; counter++)
{
accountsinFile >> statement[counter].acct_num >> statement[counter].name >> statement[counter].acct_bal;
}
cout << statement<< endl;
// keeps program open untill user enters a key
cout.setf (ios::showpoint );
cout.setf( ios::fixed);
cout << setprecision(2);
cout << "\n\n Press Enter to continue" << endl;
cin.ignore();
char ch = cin.get();
return 0;