Preview:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
	ofstream outfile("grades.txt", ios::out);
	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();

}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter