#include<fstream>#include<iostream>usingnamespacestd;
intmain(){
ofstream fout; //object is created of ofstream
fout.open("number.txt",ios::out);//ios::out opens the file for writing i.e.,in output mode if(fout) //if file is created or not cout<<"File successfully created :\n";
elsecout<<"File not created:";
//No from 1 to 100 for(int i=1;i<=100;i++)
{
fout<<i; //write no. from 1 to 100 in file
}
if(fout!=0)//if file is not emptycout<<"No. has been written in the file";
elsecout<<"No. is not written ";
fout.close();// it flushes the buffer before terminating the connection of the file return0;
}
Comments