Created
June 20, 2020 10:04
-
-
Save 2hanX/5f68b74e89592772440324668959d081 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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