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

Hello! Looking for some C++ help. Please read the question below and make sure t

ID: 3773418 • Letter: H

Question

Hello! Looking for some C++ help. Please read the question below and make sure to follow all of the guidelines. Please do not cut and paste from other questions on the net and keep as simple as possible. Thanks!!

Write a program that opens a local file C:DataDirectorydata.txt reads in the data into your program without removing the data from the file and appends new data onto the end of the existing data in the program, and then appends the new data onto the existing data within the file.
For example, if the data file originally contained the following data:

Hello

Then when your program is done, it should say:

HelloHello my name is Bob

Also, you must utilize exception handing technique to validate that the file has been open, and offer the user a chance to enter a correct filename until the file is found.

Hint: Use the overloaded open functions, or use random access methodology.

Explanation / Answer

#include<iostream>

#include<fstream>

#include<string>

using namespace std;

#include<iostream>

#include<string>

#include <fstream>

using namespace std;

int main()

{

ifstream file;

file.open ("Input.txt");

if (!file)

{

cout<<"File is not opened";

}

//ifstream file("Input.txt","w")

ofstream filePtr("Input.txt", ios::app);

string line,text;

while(!file.eof())

{

getline(file, line);

cout<<line<<endl;

}

file.close();

cout<<"Enter the text you want to append:";

getline(cin,text);

filePtr<<text<<endl;

filePtr.close();

system("pause");

return 0;

}

Sample output:

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