1. Writing to a file #

Created Saturday 25 April 2020

#include<fstream>

int main()
{
	// provide the modes app, trunc - by default trunc is assumed
	// create an object to handle the file

	ofstream outfile("my.txt", ios::app); // it'll create a file(if it doesn't exist), else it will open the file

	// or outfile.write("my.txt", ios:app);

	outfile << "Hello" << endl;
	outfile << 25 << endl;

	//closing the file - very important
	outfile.close(); // it's free now - i.e the OS knows that we have freed the file for other programs
}