Answer:
The C++ code is given below. The highlighted code is essential for reading the file. Appropriate comments given guide for better understanding
Explanation:
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
int acctNumber;
string accountType;
double balance;
// openfile
ifstream infile ("inputfile.txt");
if (infile.is_open())
{
while (true)
{
// reading from file
infile >> accountType;
infile >> accountType;
infile >> balance;
// break loop when end of file reached
if( infile.eof() )
break;
}
// close file
infile.close();
}
else
cout << "Unable to open file";
return 0;
}