address of the first record in the array + (account number - 1000) * sizeof(int).
I am supposed to read this file into 4 separate arrays. And, be able to request a user-entered account number and display the corresponding name and account balance. This is all I come up with so far, but not really sure how to use that formula.
Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string filename = "bank.dat";
const int CUSTOMERS=5;
int i=0, acctNum[CUSTOMERS];
string firstName[CUSTOMERS], lastName[CUSTOMERS];
float balance[CUSTOMERS];
ifstream inFile;
inFile.open(filename.c_str());
if(inFile.fail())
{
cout<<"\nThe file named "<<filename<<" was not successfully opened"
<<"\nPlease check that the file currently exists."
<<endl;
exit(1);
}
cout<<"\nThe file has been successfully opened for reading."
<<endl<<endl;
inFile>>acctNum>>firstName>>lastName>>balance;
cout<<"\nEnter the account number for the customer you are looking for: "<<endl;
inFile.close();
return 0;
}
this line also gives me this error: error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'int [5]' (or there is no acceptable conversion)
Code:
inFile>>acctNum>>firstName>>lastName>>balance;