In this program, we are going to share C++ program to create a file. If you are a C++ beginner and want to learn C++ programming, then keep your close attention in this tutorial as I am going to share a C++ program to create a file with the output.
Copy below C++ program and execute it with Turbo C compiler to see the output of the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> #include <fstream> using namespace std; int main() { fstream file; file.open("sample-file.txt",ios::out); if(!file) { cout<<"Getting error while creating file!"; return 0; } cout<<"Your file has been created successfully."; file.close(); return 0; } |
Your file has been created successfully.
Liked this program? Do Like & share with your friends.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.