Buffering

#include <fstream>;
using namespace std;

int main(){
	ofstream outFile("myFile.txt");
	outFile << "ECE" << endl;
	outFile << "244" << endl;
	outFile.close();
	return 0;
}

The above example will flush to the file after “ECE” and also “244”. If we want to flash at the end, we can do two things: we can do the endl; or we can do flush().

#include <fstream>;
using namespace std;

int main(){
	ofstream outFile("myFile.txt");
	outFile << "ECE";
	outFile << "244";
	
	outFile << endl;
}
#include <fstream>;
using namespace std;

int main(){
	ofstream outFile("myFile.txt");
	outFile << "ECE";
	outFile << "244";
	
	outFile.flush();
}

Handling I/O Errors

int x, y;
cin >> x >> y;

What happens during error

int x, y;
cin >> x >> y;

Summary:

Solving Procedure