The fstream library allows us to work with files.

To use the fstream library, include both the standard <iostream> AND the <fstream> header file:

Example

#include <iostream>
#include <fstream>

There are three classes included in the fstream library, which are used to create, write or read files:

Class Description
ofstream Creates and writes to files
ifstream Reads from files
fstream A combination of ofstream and ifstream: creates, reads, and writes to files



Practice Excercise Practice now