#include<iostream>
#include<fstream>
#include<cstdlib>
const int size = 60;
using namespace std;
int main()
{
char filename[size];
ifstream inFile;
cout << "Pleasr enter text name: "<<endl;
cin.getline(filename,size);
inFile.open(filename);
if (!inFile.is_open())
{
cout << "could not open the file " << filename <<endl;
cout << "Program terminating.\n";
exit (EXIT_FAILURE);
}
char ch;
int count;
inFile>>ch;
while(inFile.good())
{
if (ch>=0&&ch<=127)
count ++;
inFile>>ch;
}
if(inFile.eof())
cout << "End of file reached.\n";
else if(inFile.fail())
cout<< "Input terminate by data mismatch."<<endl;
else
cout << "Input terminate for unknown reson."<<endl;
if(count == 0)
cout << "No date processed"<<endl;
else
cout << "It's have : " << count <<" char" <<endl;
inFile.close();
return 0;
}
6.8c++prohomework
最新推荐文章于 2024-08-12 16:55:46 发布