Need Programming Assignment Help?

Get Help with Programming Assignment in Java, C/C++, Dot Net, PHP, Database and UML Diagrams

C++ Program File Handling

C++ Program File Handling to create a file

This is the C++ Programming example for File Handling to create a new 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;
}