- 24
- 0
- 约6.14千字
- 约 8页
- 2016-10-11 发布于重庆
- 举报
统计字符串中各个字符的个数
#includeiostream
#includefstream
#includestring
#includesstream
using namespace std;
char a[100]; //字符数组
int b[100]; //字符个数
double p_a[100]; //字符概率数组
int sum=0; //字符总数
//判断当前字符temp是否已出现过
bool search(char temp,char a[],int m,int n)//m为数组a的元素总个数,即100;n为当前数组a中存放的字符种类的个数
{
int i=0;
while(in)
{
if(a[i]==temp) return true;
else i++;
}
return false;
}
//求各个字符的个数,放在数组b中
void read_file( string file_name = test_data.txt )
{
int k=0;
ifstream file( file_name.c_str() ); //将string转化为char数组
char temp;
if ( file.is_open() == true ) //检查文件是否打开
原创力文档

文档评论(0)