Image

Programs - C++ - File Handling

Program:


#include<fstream.h>
#include<conio.h>
void main()
{
int num;
  ifstream fin;
  fin.open("nums.cpp");
  ofstream ofout,efout;
  efout.open("even.cpp");
  ofout.open("odd.cpp");
//int num;

  clrscr();
while(!fin.eof())
  {
  fin>>num;
  if(num%2==0)
  {
   efout<<num;
   efout<<"\n";
  }
  else
  {
   ofout<<num;
   ofout<<"\n";
  }
  }
cout<<"nos. stored";
  efout.close();
  ofout.close();
  fin.close();
  getch();
 }