C++ Program to create a txt or binary file File


#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
void main()
{  clrscr();
   char str[50], c;
   int cnt=0;
   fstream f("mydata.dat",ios::binary|ios::in);
   if (!f)
   {  cout<<"\n could not find";
      getch();
      exit(-1);
   }
   cout<<"\n THE SENTENCE IS : ";
   while (!f.eof())
   {  f.get(c);
      cout<<c;
      if (isalpha(c))
      {  cnt++;
      }
   }
   f.close();
   cout<<"\n number of characters are : "<<cnt;
   getch();
}
Share:

0 comments: