n this article we will discuss and write a program to create a text file in the first place and then the program will write in the file by itself. To create a program like this we have to use fstream.
The program will create a text file and if the file is created then it will show “file created successfully” otherwise it shows “Error in creating file!!!”.
Declare fstream file class and open the text file in writing mode. Program will look for the file in the current directory if the file is not present then it creates a new text file. Then it will add text or data into the file. After that we have to close the file.
for more you can check the link given below