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.
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";
	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 << ":";

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