>>流读入操作符
效果类似与cin>> 遇到空白符停止
1.打开文件
2.按字符读入
3.统计字母个数
#include<iostream>
#include<fstream>
using namespace std;
bool isalpha(char c) {
if ((c >= 'a'&&c <= 'z') || (c >= 'A'&&c <= 'Z'))
return true;
return false;
}
int main() {
int cnt=0;
fstream file;
file.open("data.txt", ios::in);
if (file.fail()) {
cout << "File not found" << endl;
return 1;
}
char c;
while (file >> c) {
if (isalpha(c))cnt++;
}
file.close();
cout << cnt << endl;
return 0;
}