DEV Community

Lalit Kumar
Lalit Kumar

Posted on

How to create a text file in C++ and write in it?

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!!!”.

Approach

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

https://www.kodlogs.com/blog/2238/how-to-create-a-text-file-in-c-and-write-in-it

Top comments (0)