1、统计可显示字符的频数
代码:
//统计可显示字符频数
#include<iostream>
#include<fstream>
#include<map>
using namespace std;
int main()
{
ifstream infile("dictionary.txt",ios::in);
map<char,int>wordCount;
char asc; //
while(infile>>asc)
{
if(isprint(asc))//宏定义,判断arc是否为可显示打印字符
wordCount[asc]++;
}
for(map<char,int>::iterator it=wordCount.begin();it!=wordCount.end();it++) //迭代器
{
cout<<(it->first)<<" "<<(it->second)<<endl;
}
return 0;
}
结果:
2、重叠词汇量
代码:
//重叠词汇量
#include<fstream>
#include<iostream>
#include<string>
#include<map>
#include<string>
using namespace std;
/*
//输出找到的单词
voi