- #include<iostream>
- #include<fstream>
- int b[128]={0}
- using namespace std;
- int main()
- {
- string fileName;
- cin>>fileName;
- char*fileN=new char,ch;
- for(int i=0;i<fileName.size();i++)
- {
- fileN[i]=fileName[i];
- }
- fileN[fileName.size()]='\\0';
- ifstream file(fileN,istream::in);
- if(!file.is_open())
- {
- cout<<"error";
- return 1;
- }
- while(file.get(ch))
- {
- b[ch]++;
- }
- if(file.eof())
- cout<<"Eof reached"<<endl;
- else
- cout<<"error reading"<<endl;
- file.close();
- for(int i=0;i<128;i++)
- cout<<(char)i<<"\\t"<<b[i]<<endl;
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1006201512840.html
来源: http://www.codesnippet.cn/detail/1006201512840.html