Question #210013

Topic: Files and Streams


Codes discussed will be posted here. Write your conclusion on the File stream discussion. 


Filename: "Ch5_AccountBalance.cpp"


Given problem and code: Please use the link below

-->>https://drive.google.com/file/d/1tDK28GtTpqbQ_sSKVkpdTQFJQz3gtlcB/view?usp=sharing


*Note: Need the proper codes

*Note need proper codes and conclusion on how its done and about the results. And please give the proper solution and explanation.

Note: Place your conclusion on why did it turn out like that and give your reasons why the results turned like that, one paragraph will do for the explanation and conclusion.


Expert's answer

#include <fstream>
#include <iostream>
using namespace std;
  
int main ()
{
    char data[100];
  
    // opening a file in write mode.
    ofstream myfile;
    myfile.open("E:\\message.txt");
  
    cout << "Writing to the file" << endl;
    cout << "Enter your name: ";
    cin.getline(data, 100);
  
    myfile << data << endl;
  
    cout << "Enter your age: "; cin >> data;
    cin.ignore();
  
    myfile << data << endl;
  
    // close the opened file.
    myfile.close();
  
   // opening a file in read mode.
   ifstream infile;
   infile.open("E:\\message.txt");
  
   cout << "Reading from a file" << endl; infile >> data;
  
   cout << data << endl; infile >> data;
   cout << data << endl;
  
   infile.close();
    
   return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS