Basic File Processing Operations


Data Type Description
ofstream represents the output file stream. used to create files and to write information to files.
ifstream represents the input file stream. used to read information from files.
fstream represents the file stream generally. has the capabilities of both ofstream and ifstream (Can create files, write information to files, and read information from files)

void open (const char *filename, ios::openmode mode);

const char * filename specifies the name and location of the file to be opened

ios::openmode mode defines the mode in which the file should be opened

Data Type Description
ios::app Append mode. All output to that file to be appended to the end.
ios::ate Open a file for output and move the read/write control to the end of the file
ios::in Open a file for reading
ios::out Open a file for writing
ios::trunc If the file already exists, its contents will be truncated before opening the file.

fstream outfile; 
outfile.open("file.dat", ios::out | ios::in);
Data Type Description
ios::beg for positioning relative to the beginning of a stream.
ios::cur for positioning relative to the current position in a stream
ios::end for positioning relative to the end of a stream