Suppose that infile is an ifstream variable and it is associated with the file that contains the following data: 27306 savings 7503.35. Write the C11 statement(s) that reads and stores the first input in the int variable acctNumber, the second input in the string variable accountType, and the third input in the double variable balance.

Respuesta :

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;

}