My assignment this week is to simply "Write a program that asks the user to enter a name of a file. The program should display the number of characters in the program.
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
char file_name[81];
char ch;
cout<<"Enter the name of a file: ";
cin.getline(file_name, 81);
fstream file(file_name, ios::in | ios::out | ios::binary);
if (!file)
{
cout<<endl;
cout<< "ERROR: Could not open file. " ;
exit(1);
}
while( (ch = file.get()) !=EOF)
{
file.seekg(0, ios::end);
cout<<file.tellg();
}
file.close();
cout<<"Program Terminated."<<endl;
system("PAUSE");
return 0;
}