calculate the number of characters-统计文件中的字符数,非空白字符数,字母数,输入到文件和屏幕:
2014-09-02 20:41
471 查看
calculate the number of characters-统计文件中的字符数,非空白字符数,字母数,输入到文件和屏幕:
//calculate the number of characters-统计文件中的字符数,非空白字符数,字母数,输入到文件和屏幕: #include<iostream> #include<fstream> #include<cstdlib> #include<cmath> int main() { using namespace std; ifstream fin; ofstream fout; double ch1 = 0,ch2 = 0,letter = 0; char tem; fin.open("infile.dat"); if(fin.fail()) { cout<<"Input file opening failed.\n"; exit(1); } fout.open("outfile.dat"); if(fin.fail()) { cout<<"Output file opening failed.\n"; exit(1); } while(fin.get(tem)) { ch1 ++; ch2 ++; if(tem == ' ') ch2--; if((tem >= 'a' && tem <= 'z') || (tem >= 'A' && tem <= 'Z')) letter++; } ch1--; ch2--; cout<<"The numbers of character is "<<ch1<<endl; cout<<"The numbers of character except empty characters is "<<ch2<<endl; cout<<"The numbers of letter is "<<letter<<endl; fout<<"The numbers of character is "<<ch1<<endl; fout<<"The numbers of character except empty characters is "<<ch2<<endl; fout<<"The numbers of letter is "<<letter<<endl; fin.close(); fout.close(); return 0; }文件:
1 2 3 4 5 6 7 8 9 10 a输出文件:
To outfile.dat The numbers of character is 21 The numbers of character except empty characters is 11 The numbers of letter is 1输出屏幕:
The numbers of character is 21 The numbers of character except empty characters is 11 The numbers of letter is 1
相关文章推荐
- 第13周-项目1-小玩文件-用键盘输入文件名,统计输出文件中每个字母、数字字符出现的次数
- 汇编“从键盘输入一串字符,分别统计其中字母、数字和其
- 输入一行字符,分别统计出其中英文字母 空格 数字 和其他字符的个数
- 输入一行字符,分别统计出其中的英文字母,空格,数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- C编程之旅:字符统计之文件输入
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- 输入一行字符,分别统计出其中英文字母、数字字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- [Java]练习题007: 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。.Cpp
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- [Java]练习题007: 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
- 【程序17】输入一行字符,分别统计其中英文字母、空格、数字和其它字符的个数