Q:

C++ program to create a file

0

C++ program to create a file

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Creating a file using file stream.

//C++ program to create a file.

#include <iostream>
#include <fstream>
 
using namespace std;
 
int main()
{
   fstream file; //object of fstream class
    
   //opening file "sample.txt" in out(write) mode
   file.open("sample.txt",ios::out);
    
   if(!file)
   {
       cout<<"Error in creating file!!!";
       return 0;
   }
    
   cout<<"File created successfully.";
    
   //closing the file
   file.close();
    
   return 0;
}

Output

 
File created successfully.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now