Number of Bytes in a Text file

// Number of Bytes in a Text File.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "fstream"
#include "iostream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
       int c = 0;
       char ch,file[30];
       cout <<" Enter the name of the file: " << "\n";
       gets_s(file);
       fstream fl;
       fl.open(file,ios::in);
       if (fl.bad())
       {
             cout << "File can not be opened." << "\n";
             exit (0);
       }
       if(fl.good())
       {
             cout << " The current contents of the file are: " << "\n";
             while(fl);
             {
                    fl.get(ch);
                    c++;
                    cout << ch;
             }
       }
       cout << " Total no. of Bytes are" << c << "\n";
       fl.close();
       cout << "PRess Enter key to continue..." << "\n";
       system("pause");
       return 0;
}



Share on Google Plus