c++ program to write 1 to 100 in a file.














































c++ program to write 1 to 100 in a file.



#include<fstream> #include<iostream> using namespace std; int main() { 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"; else cout<<"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 empty cout<<"No. has been written in the file"; else cout<<"No. is not written "; fout.close();// it flushes the buffer before terminating the connection of the file return 0; }

Comments