Ask Question

Suppose that infile is an ifstream variable and it is associated with the file that contains the following dа ta: 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.

+4
Answers (1)
  1. 19 May, 12:42
    0
    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

    #include

    #include

    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;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Suppose that infile is an ifstream variable and it is associated with the file that contains the following dа ta: 27306 savings ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers