Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@2hanX
Created June 20, 2020 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2hanX/5f68b74e89592772440324668959d081 to your computer and use it in GitHub Desktop.
Save 2hanX/5f68b74e89592772440324668959d081 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<fstream>
using namespace std;
const int SIZE = 100;
int main()
{
char filename[SIZE];
ifstream inFile;
cout << "Enter the file name: ";
cin.getline(filename, SIZE);
inFile.open(filename);
int cnt = 0;
if (!inFile.is_open())
{
cout << "couldn't open file." << endl;
exit(1);
}
char value;
inFile >> value;
while (inFile.good())
{
cnt++;
inFile >> value;
inFile.get();
}
if (inFile.eof())
cout << "End of file reached.\n";
else if (inFile.fail())
cout << "Input terminated for unknown reason.\n";
if (cnt == 0)
cout << "No data processed.";
else
{
cout << "there are " << cnt << " characters." << endl;
}
inFile.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment