Question: Combine the following programs to do the following: a. Create the file Friends.txt b. Based on users input, write the names of three friends to

Combine the following programs to do the following: a. Create the file Friends.txt b. Based on users input, write the names of three friends to the Friends.txt file c. Read the three names from the Friends.txt file and display (to the screen) the three names d. Close the file //This program writes user input to a file. #include #include #include using namespace std; int main() { ofstream outputFile; string name1, name2, name3; // Open an output file. outputFile.open("Friends.text"); //Get the names of three friends. cout << "Enter the names of three friendss. "; cout << "Friend #1: "; cin >> name1; cout << "Friend #2: "; cin >> name2; cout << "Friend #3: "; cin >> name 3; // Write the names to the file. outputFile << name1 << endl; outputFile <

***Program 2 // This program reads data from a file. #include #include #include using namespace std;

int main() { ifstream inputFile; string name; inputFile.open("Friends.text"); cout << "Reading data from the file. "; inputFile >> name; cout << name << endl; inputFile >> name; cout << name <> name; cout << name << endl inputFile.close(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!