我需要读取一个文件,然后统计文件中的英文单词,这个方法可以,但是如果文件中出现日语,就会统计出错 ,有人告诉我,要我排除双字节字符,我试过,没成功,应该怎么操作呢?
string word = "";
char ch;
int total=0;
fstream outFile;
fstream inFile;
inFile.open(strReadFilePath, ios::in);
while (inFile.get(ch))
{
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '\''))
word += ch;
else
{
if(word == "")
continue;
words[word]++;
word = "";
}
}
if(word != "")
{
words[word]++;
}
ASCII码的高字节全为0,用这个思路去判断