Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that works external file* Create functions to perform the follo

ID: 657561 • Letter: C

Question



Create a program that works external file* Create functions to perform the following actions: creation. We append and lie read Objective: Create use and pass filestream that input/ output data to and from external files Lab Procedure: Write the function to create n Ines of a use named output file Write the function to append n lines to an existing file Write the function to read a user selected file and display it on the console. Al file to streams are declared in the main function. The main function rogues! the filename from the user. No Global variables. All console input and output should be formatted and easy to read. FILE FORMAT: All external files will consist of lines that contain three (3) of following datatypes: int double, bool. char or string Lab Report: Follow the standard Lab format Documentation: Document your code to ensure that others could re-use your code Hints: file stream external files

Explanation / Answer

ANSWER

Writing Data to a File

#include <fstream>

int main()

{

    ofstream write;

    write.open ("File.txt");

    write << " write to a file opened from program. "; // Writing data to file

    cout<<"Data has been written to file";

    write.close(); // Closing the file

}

--------------------------------------------------------------------------------------------------

Appending Data to a file

#include <fstream>

int main()

{

    ofstream append;

append.open ("File.txt", ios::app); // Append mode

  append << "I am writing to a file opened from program. ";

    cout<<"This is appended to file";

    append.close();

}

--------------------------------------------------------------------------------------------------------

Reading Data from File

#include <iostream>

#include <fstream>

#include <string>

int main()

{

    string fread;

    ifstream read ("File.txt");

    if (read.is_open())

    {

        while ( getline (read, fread) )

        {

            cout << fread << endl;

        }

read.close();

    }

    else cout << "error in reading";

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote