计算数组中的字母.C++

Counting letters in an array. C++

本文关键字:C++ 数组 计算      更新时间:2023-10-16

很抱歉,如果措辞/术语不尽可能准确,我对这种编码方法还比较陌生。

所以我有一个名为somefile.txt的.txt文件该文件的内容如下:

24 234 14
a8 267 35
35 378 28
b5 467 29

文件加载如下:

#include <iostream>
#include <istream>
#include <fstream>
#include <string>
int main (){
ifstream inputfile;
inputfile.open("somefile.txt");
string contents;
while(!inputfile.eof())
    {
        getline(inputfile, contents);
        cout << contents;
    }
inputfile.close();
}

我现在想做的是找出这个文件和其他相同格式和类似.txt文件中有多少个字母。例如,somefile.txt有两个字母,当人类看到文件内容时,它们可以被识别。有没有办法让计算机知道/计算有多少个字母。我还希望,如果可能的话,这可以在一个单独的功能中完成。

希望这能澄清我以前糟糕的写作。再次感谢

查看ctype.h并使用isletter或isalpha等。http://www.cplusplus.com/reference/cctype/