Answer to Question #274050 in C++ for Amit

Question #274050

Write a program to create a file and input user defined value to it. Then append new contents and print all the contents from file to output screen.

1
Expert's answer
2021-12-09T07:29:57-0500
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
    ofstream fout;  // Create Object of Ofstream
    ifstream fin;
    fin.open("a.txt");
    fout.open ("a.txt",ios::app); // Append mode
    if(fin.is_open())
        fout<< "\n Writing to a file opened from program.\n"; // Writing data to file
    cout<<"\n Data has been appended to file";
    fin.close();
    fout.close(); // Closing the file
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment