2

PHOTO EMBED

Tue Apr 27 2021 00:59:12 GMT+0000 (Coordinated Universal Time)

Saved by @ahmedqgqgq #java

ios::in allows input (read operations) from a stream.
ios::out allows output (write operations) to a stream.
| (bitwise OR operator) is used to combine the two ios flags,
meaning that passing ios::in | ios::out to the constructor
of std::fstream enables both input and output for the stream.
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
	ofstream outfile("grades.txt", ios::out);//ios::out Write operations.
	if (!outfile)
	{
		cerr << "error:output file cannot be opened\n";
		exit(1);
	}
	char id[9], name[16];
	int grade;
	cout << "\t:";
	int n = 1;
	while (cin>>id>>name>>grade)
	{
		outfile << name << " " << id << " " << grade << endl;
		cout << "\t" << ++n << ":";
	}
	outfile.close();

}
content_copyCOPY