Question: write a C++ program to write / read data to / from a file. You need to include library. a. The first part of the
write a C++ program to write / read data to / from a file. You need to include


a. The first part of the program writes the grades for 3 students to a local file. Declare a variable of type ofstream which is used to output a stream into a file: ofstream output; // output is the name of the variable Use the following function (open) to create a text file on your local drive: output.open("grades.txt"); // grades.txt is the name of the file Prompt the user to input values for the grades of 3 students. 11 Use the output operator (>) to read data from the above file: input >> scorel >> score2 score3; // the values on the file will be stored in the above variables Use cout to display the above values. Close your file: input.close()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
