Problem Statement - Empty File Creation
Creating an empty file using ofstream class
- Learning to use ofstream class in its simplest form.
- Learning to use the close() method of ofstream class.
Solved Problem Understanding
#include <fstream.h> //This header file is required for data file handling classes
using namespace std;
For using creation of a file we use ofstream class (output file stream) with filename as parameter. This will create a file on the disk without any content (empty file). fout is the object name selected by us. we can give any name to this object.
cout<<“File Created Successfully”<<endl;
Displays that file has been created.
Here we are using the close method of ofstream along with the object name prefix.
- This is the simplest way of creating a file, but for practical purposes we must check if the file has been created.
- one can also make this program using fstream class which has capability of using both in input as well as output mode.
- It is important to give file name as string literal or a null terminated pre-initialised char array.
Suggested Filename(s): filecrea.cpp,file-create.cpp