+ 6
<fstream> is the header file which includes ifstream and ofstream functionalities.
ifstream refers to 'input file stream'
ofstream refers to 'output file stream'
Note that they are streams - You may see <fstream> as an alternate of <iostream>.
i.e.
<iostream> contains cin and cout functions.
cin utilises >>
cout utilises <<
Similarly, after including <fstream>, you may define variables to store or to write information to files.
ifstream inData;
string str;
// inData is now responsible for file input stream
// and we can store a string from the file into str
// by using inData
inData.open("text.txt");
inData >> str;
inData.close();
// to write str to another file
ofstream outData;
outData.open("text2.txt");
outData << str;
outData.close();
Note that outData and inData can be declared as you like, e.g. outputData, InFileData, etc.
Note that the operators of ifstream and ofstream is similar to cin and cout, this makes it easier to remember the syntax and utilise them.