File handling in Object Oriented Programming:

To perform input and output from files, C++ provides the fstream library. It defines several classes including ifstream and ofstream.
We connect stream object to the physical file by creating a stream object by specifying the name of the file as the argument.
#include <fstream>
ofstream outfile(“output”);
ifstream infile(“input”);
Alternatively, the file can be connected by using the open member function with one or more arguments
#include <fstream>
ofstream outfile;
ifstream infile;
infile.open(“input”);
outfile.open(“output”, ios:: app | ios :: nocreate); // do not create a new file, append at the end of file
The file should be disconnected by using close member function. To access and manipulate contents of the file, get, put, read and write methods are provided.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: